August 2016
Beginner to intermediate
717 pages
15h 24m
English
The default project layout created by the startproject command does not define a location for your templates. This is very easy to fix. Create a directory named templates in your project's root directory. Add the TEMPLATE_DIRS variable in your settings.py:
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
That's all. For example, you can add a template called about.html and refer to it in the urls.py file as follows:
urlpatterns = patterns(
'',
url(r'^about/$', TemplateView.as_view(template_name='about.html'),
name='about'),Your templates can also reside within your apps. Creating a templates directory inside your app directory is ideal to store your app-specific templates. ...
Read now
Unlock full access