I am learni开发者_如何学运维ng Django through the djangobook website and everything is going well, but the latest project I created (deals with templates) is showing all of the html tags in the web page - how do I eliminate them?
views.py:
def current_datetime(request):
now = datetime.datetime.now()
return render_to_response('current_datetime.html',{'current_date':now})
base.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>
current_datetime.html:
{% extends "base.html" %}
{% block title %}The current time{% endblock %}
{% block content %}
<p>It is now {{ current_date }}.</p>
{% endblock %}
Unfortunately, instead of it displaying the page as it is supposed to, it is displaying all of the HTML tags with it.
in you urls.py
from mysite.views import current_datetime
urlpatterns = patterns('',
(r'^time/$', current_datetime),
)
the template name must be equal to name in view current_datetime.html
in the terminal runserver this way
$ python manage.py runserver
精彩评论