首先是我的Template 文件名为sample.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>
然后我调用我的Template,调用文件名为ahead.html
{% entends 'sample.html' %}
{% block title %} Future time {% endblock %}
{%block content %}
In {{hour}} hour(s) is {{ nextdate }}.
{% endblock %}
然后我在view中这样写的
def hours_ahead(request,offset):
hour=int(offset)
nextdate=datetime.datetime.now()+datetime.timedelta(hours=hour)
return render_to_response('ahead.html',{'hour':hour},{'nextdate':nextdate})
我在URL中这样写的
from mysite.view import hours_ahead
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^time/$',current_datetime),
url(r'^time/plus/(\d{1,2})/$',hours_ahead),
]
但访问页面的时候有以下报错!
Error during template rendering
In template D:\Users\rongweiwei799\mysite\mysite\templates\ahead.html, error at line 1
Invalid block tag: 'entends'
1
{% entends 'sample.html' %}
2 {% block title %} Future time {% endblock %}
3 {%block content %}
4
In {{hour}} hour(s) is {{ nextdate }}.
5 {% endblock %}
TemplateSyntaxError at /time/plus/3/
Invalid block tag: 'entends'
Request Method: GET
Request URL: http://127.0.0.1:8000/time/plus/3/
Django Version: 1.8.6
Exception Type: TemplateSyntaxError
Exception Value:
Invalid block tag: 'entends'
entends -> extends