I know somewhat about Python but certainly no expert am I am currently learning how to develop in Django 1.7. I have done Djangos tutorial am am starting my first project in it.
The project is only trying to create a static home page (at this stage) but I want to use the html templating language to get a consistent look and feel across all eventual site pages.
To cater for this I created the file called base.html in a templates folder under the project root folder. This file contains:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>(% block pagetitle %}page tile here{% endblock %}</title>
</head>
<body>
<div class="container">
{% block contents %}Page contents{% endblock %}
</div>
</body>
</html>
I have also created an app called psges in which I have created a folder called templates and with it, another folder called pages. within this folder I have created the file called index.html which contains:
(% extends 'base.html' %}
{% block pagetitle %}
Alex Pittendreigh
(% endblock %}
{% block contents %}
<h1>Welcome</h1>
<p>Cras justo odio, dapibus. Fusce dapibus, tellus ac cursus commodo,</p>
{% endblock %}
Yeah I know, bare bones stuff but I want to get the basic functionality happening before adding in the styling.
I have created the TEMPLATE_DIRS entry and added the app in the sites settings.py file and also created my route and view.
I did a manage.py check command and it reported no errors in code.
Finally ran manage.py runserver (again no errors) and tried to navigate to the page in Chrome (version 41.0) I get a TemplateSyntaxError exception with the value of "Unclosed tag 'block'. Looking for one of: endblock".
My view seems to be working OK as I can see some of the html code in the stack trace. The highlighted line is straight after the {% extends 'base.html' %} line.
I have a copy of the Django 1.7 manual in PDF and also Googled and as far as I can determine all I needed to do was include the templates path for the root templates folder in my settings.py file as Django will aautomatically search for templates folders in each app. This entry in my setting file contains:
TEMPLATES_DIR = [
os.path.join(BASE_DIR, 'templates'),
],
I am also configured to use a MySQL 5 database but not hitting it with any code as yet.
Obviously I'm missing something here. Can anyone help please.
There is a typo in your base.html
. Note the (%
that should be {%
instead:
<title>(% block pagetitle ...