Django Prototype is a simple application which allows you to harness the power of the Django templating system to produce an interactive HTML site.
The template we load is derived from the url path. For example,
http://localhost:8000/example/ will seek to load the template
templates/example.html
with context specified in prototype.yml
file.
- Build-in Livereload support.
- Build-in Sass support.
- Possibility to provide context for Django templates.
- Django staticfiles support.
- Support for Django's reverse resulution of named urls.
Install django-prototype
:
$ pip install django-prototype
Create your first template at templates/index.html
:
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>blah</title>
</head>
<body>
<p>{{ content }}</p>
</body>
</html>
Create prototype.yml
file:
urls:
/:
context:
content: It works!
And done. You can see it in browser by running:
$ prototype
and opening http://localhost:8000/ in your browser.
While prototype
command is running, you can edit you templates and changes
will be displayed automatically in the browser window.
All your static files should go to static
directory and added to templates
using static
tag:
{% load static %}
<img src="{% static "img/example.png" %}" alt="just another example" />
In this example, img/example.png
will be loaded from
static/img/example.png
.
First you need to define name of your url in prototype.yml
:
urls:
/my/page/:
name: mypage
And then, you can use it in tamplates:
<a href="{% url 'mypage' %}">My page</a>
Now, even you change urls, they will work as long as name points to the right url.