32
32
TEMPLATES = [
33
33
{
34
34
'BACKEND': 'django.template.backends.django.DjangoTemplates',
35
- 'DIRS': [ # your template dirs here
35
+ 'DIRS': [ # your template dirs here
36
36
],
37
- 'APP_DIRS': False,
37
+ 'APP_DIRS': False,
38
38
'OPTIONS': {
39
39
'context_processors': [
40
40
'django.contrib.auth.context_processors.auth',
@@ -47,30 +47,31 @@ Setup
47
47
'django.template.context_processors.request',
48
48
],
49
49
'loaders': [
50
- 'django.template.loaders.filesystem.Loader',
51
- 'django.template.loaders.app_directories.Loader',
52
- 'dbtemplates.loader.Loader',
50
+ 'django.template.loaders.filesystem.Loader',
51
+ 'django.template.loaders.app_directories.Loader',
52
+ 'dbtemplates.loader.Loader',
53
53
],
54
54
},
55
55
},
56
56
]
57
57
58
- Order of ``TEMPLATES.OPTIONS.loaders`` is important. In the former example, templates from database
59
- will be used as a fallback (ie. when template does not exists in other locations).
60
- If you want template from database to be used to override templates in other locations,
61
- put ``dbtemplates.loader.Loader`` at beginning of ``loaders``.
58
+ The order of ``TEMPLATES.OPTIONS.loaders`` is important. In the former
59
+ example, templates from the database will be used as a fallback (ie. when
60
+ the template does not exists in other locations). If you want the template
61
+ from the database to be used to override templates in other locations,
62
+ put ``dbtemplates.loader.Loader`` at the beginning of ``loaders``.
62
63
63
- 4. Sync your database ``python manage.py syncdb ``
64
+ 4. Sync your database ``python manage.py migrate ``
64
65
5. Restart your Django server
65
66
66
- .. _Git repository: http ://github.com/jazzband/django-dbtemplates/
67
+ .. _Git repository: https ://github.com/jazzband/django-dbtemplates/
67
68
68
69
Usage
69
70
=====
70
71
71
72
Creating database templates is pretty simple: Just open the admin interface
72
73
of your Django-based site in your browser and click on "Templates" in the
73
- "Dbtemplates " section.
74
+ "Database templates " section.
74
75
75
76
There you only need to fill in the ``name`` field with the identifier, Django
76
77
is supposed to use while searching for templates, e.g.
@@ -84,44 +85,3 @@ other template loaders. For example, if you have a template called
84
85
contents in the database, you just need to leave the content field empty to
85
86
automatically populate it. That's especially useful if you don't want to
86
87
copy and paste its content manually to the textarea.
87
-
88
- Example
89
- =======
90
-
91
- ``dbtemplates`` comes with an example Django project that let's you try it
92
- out. The example uses Django's own `flatpages app`_ to enable you to create
93
- a simple page using ``dbtemplates``. Flat pages are a perfect fit to
94
- dbtemplates since they come prepackaged and are simple to use.
95
-
96
- Here is how it works:
97
-
98
- 1. Open your command line and change to the ``example`` directory in the
99
- directory with the extracted source distribution.
100
- 2. Run ``python manage.py syncdb`` and follow the instructions.
101
- 3. Run ``python manage.py runserver`` and open your favorite browser with the
102
- address http://127.0.0.1:8000/admin/.
103
- 4. Next add a new `Template` object in the ``dbtemplates`` section and use
104
- ``flatpages/default.html`` as the value for the ``name`` field. For the
105
- ``content`` field use this example::
106
-
107
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
108
- "http://www.w3.org/TR/REC-html40/loose.dtd">
109
- <html>
110
- <head>
111
- <title>{{ flatpage.title }}</title>
112
- </head>
113
- <body>
114
- {{ flatpage.content }}
115
- </body>
116
- </html>
117
-
118
- 5. Return to the home screen of the admin interface and add a new flat page.
119
- Use ``/`` (yep, just a forward slash) and whatever ``title`` and
120
- ``content`` you prefer. Please make sure you select the default site
121
- ``example.com`` before you save the flat page.
122
- 6. Visit http://127.0.0.1:8000/ and see the flat page you just created
123
- rendered with the ``flatpages/default.html`` template provided by
124
- ``dbtemplates``.
125
-
126
- .. _flatpages app: http://docs.djangoproject.com/en/dev/ref/contrib/flatpages/
127
-
0 commit comments