0

私は Django の初心者で、アプリを使用してサンプル プロジェクトを作成しました。

ビュー.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 = 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)

urls.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>

出力変数を印刷すると、すべて問題なく表示されますが、サーバーを実行してページをポイントすると、空白のページが表示されます。

4

1 に答える 1

2

終了タグがありませ</title> ん テンプレートは次のようになります

<html>
    <head>
        <title>{{head_title}}</title>
    </head>
    <body>
        <h1>{{page_title}}</h1>
        <p>{{page_body}}</p>
    </body>
</html>
于 2013-01-06T03:32:50.670 に答える