Python httpresponse不呈现html页面
我是Django的新手,创建了一个带有应用程序的示例项目: views.pyPython httpresponse不呈现html页面,python,django,Python,Django,我是Django的新手,创建了一个带有应用程序的示例项目: views.py from django.http import HttpResponse,Http404 from django.contrib.auth.models import User from django.template import Context from django.template.loader import get_template def main_page(request): template =
from django.http import HttpResponse,Http404
from django.contrib.auth.models import User
from django.template import Context
from django.template.loader import get_template
def main_page(request):
template = get_template('main_page.html')
variables = Context({
'head_title': u'Django Bookmarks',
'page_title': u'Welcome to Django Bookmarks',
'page_body': u'Where you can store and share bookmarks!'
})
output = template.render(variables)
print 'output',output
return HttpResponse(output)
url.py
from django.conf.urls.defaults import patterns, include, url
from bookmarks.views import *
urlpatterns = patterns('',
(r'^$',main_page),
(r'^user/(\w+)/$',user_page),
#(r'login/$','django.contrib.auth.views.login')
)
main_page.html
<html>
<head>
<title>{{head_title}}</h1>
</head>
<body>
<h1>{{page_title}}</h1>
<p>{{page_body}}</p>
</body>
</html>
{{head_title}}
{{page_title}}
{{page_body}}
当我打印输出变量时,我可以看到一切正常,但是当我运行服务器并指向页面时,我看到一个空白页面。您缺少结束标记
您的模板应该如下所示
<html>
<head>
<title>{{head_title}}</title>
</head>
<body>
<h1>{{page_title}}</h1>
<p>{{page_body}}</p>
</body>
</html>
{{head_title}}
{{page_title}}
{{page_body}}
查看页面源代码时,您看到了什么吗?Django书签欢迎来到Django书签,您可以在这里存储和共享书签 上面的源代码看起来很完美,但不确定为什么所有内容都是空白的参见title
标记。事实并非如此closed@soon:你应该把它作为答案贴出来。