Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/09/2011, 20:18
Garet
 
Fecha de Ingreso: agosto-2002
Mensajes: 74
Antigüedad: 21 años, 8 meses
Puntos: 1
Problema con extends en templates de Django

Hola a todos, llevo un par de días probando django y, haciendo un ejercicio copiado de un manual, he tenido un problema que no se muy bien ni porque ocurre ni como solucionarlo.

Tengo un sitio llamado prueba que contiene:
manage.py
settings.py
urls.py
views.py
y un directorio llamado templates

En settings.py tengo configurado TEMPLATE_DIRS a la ruta absoluta del directorio templates:
Código HTML:
TEMPLATE_DIRS = (
    '/home/user/prueba/templates',
)
En el directorio templates tengo 2 ficheros:

base.html
Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
  <head>
    <title>{ % block title %}{ % endblock %}</title>
  </head>
  <body>
    <h1>My helpful timestamp site</h1>
    { % block content %}{ % endblock %}
    { % block footer %}
    <hr>
    <p>Thanks for visiting my site.</p>
    { % endblock %}
  </body>
</html> 
y hours_ahead.html
Código HTML:
{ % extends "base.html" %}

{ % block title %}Future time{ % endblock %}

{ % block content %}
<p>In {{ hour_offset }} hour(s), it will be {{ next_time }}.</p>
{ % endblock %}
Y en views.py
Código HTML:
from django.shortcuts import render_to_response
import datetime

def hours_ahead(request, offset):
    offset = int(offset)
    dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
    return render_to_response('hours_ahead.html', {'hour_offset': offset, 'next_time': dt})
Al acceder a la página me da esto como resultado:
Código HTML:
{ % extends "base.html" %}
 
{ % block title %}The current time{ % endblock %}
 
{ % block content %}
<p>It is now Sept. 7, 2011, 9:13 p.m..</p> 
{ % endblock %}
Es decir, no me expande el template por "base.html" y devuelve las etiquetas tal cual.

¿Qué puede estar pasando y cúal sería la forma de solucionarlo?

Gracias