Question

I'm trying to get a very basic Django template working on a google app engine app (on my local machine, not yet deployed, if that matters), but my app is acting like it has no idea how templates work. It just prints { % extends "base.html" %} to the webpage instead of using it to load a template like so:

enter image description here

Although, the views seem to be working properly otherwise, since "{{ message }}" at least loads the correct thing. I feel like I'm just missing some silly piece of information, but I'm at a loss. I've been looking at the Django documentation for a while and I have no idea what went wrong. Here is the relevant code:

Snippet of settings.py:

TEMPLATE_DIRS = (
os.path.abspath(os.path.join(os.path.dirname( __file__ ), '..', 'hello/templates'))
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

In views.py:

from django import http
from django.shortcuts import render_to_response

def home(request):
    return render_to_response('index.html', {'message':'Hello World!'})

def form(request):
    return render_to_response('index.html', {'message':'This page will have a form.'})

In base.html (which is in the correct TEMPLATE_DIRS path):

<head>
    <title>Lunar Spring</title>
    <meta charset="utf-8">
</head>
<body>

    <div class="header">
    Some Website Name
    </div>
    <div class="content">
    { % block content %}
    { % endblock % }
    </div>

</body>

In index.html (also in that correct path):

{ % extends "base.html" % }

{ % block content % }
    {{ message }}
{ % endblock % }
Was it helpful?

Solution

Your django template syntax is not correct, watch the spaces between curly braces and percent sign.

For example, replace:

{ % extends "base.html" % }

with:

{% extends "base.html" %}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top