1

このチュートリアルを使用してフォーラムを作成しています。http://lightbird.net/dbe/forum1.html

このエラーが発生しましたが、csrf の元のモジュールがわかりません。どうすればわかりますか?

 NameError at /forum/forum/1/

 global name 'csrf' is not defined

 Request Method:    GET
 Request URL:   http://127.0.0.1:8000/forum/forum/1/
 Django Version:    1.4.3
 Exception Type:    NameError
 Exception Value:   

 global name 'csrf' is not defined

 Exception Location:    C:\djcode\mysite\forum\views.py in add_csrf, line 25
 Python Executable:     C:\Python26\python.exe
 Python Version:    2.6.0
 Python Path:   

 ['C:\\djcode\\mysite',
  'C:\\Python26\\python26.zip',
  'C:\\Python26\\DLLs',
  'C:\\Python26\\lib',
  'C:\\Python26\\lib\\plat-win',
  'C:\\Python26\\lib\\lib-tk',
  'C:\\Python26',
  'C:\\Python26\\lib\\site-packages',
  'C:\\Python26\\lib\\site-packages\\PIL']

 Server time:   Sun, 17 Feb 2013 23:21:02 +1100

エラーはここにあります。私のviews.pyで

  from django.core.urlresolvers import reverse
  from mysite.settings import MEDIA_ROOT, MEDIA_URL
  from forum.models import Forum
  from django.shortcuts import render_to_response
  from forum.models import Thread
  from django.core.paginator import Paginator, InvalidPage, EmptyPage
  def main(request):
      """Main listing."""
      forums = Forum.objects.all()
      return render_to_response("forum/list.html", dict(forums=forums, user=request.user))
  def forum(request, pk):
      """Listing of threads in a forum."""
      threads = Thread.objects.filter(forum=pk).order_by("-created")
      threads = mk_paginator(request, threads, 20)
      return render_to_response("forum/forum.html", add_csrf(request, threads=threads, pk=pk))
  def thread(request, pk):
      """Listing of posts in a thread."""
      posts = Post.objects.filter(thread=pk).order_by("created")
      posts = mk_paginator(request, posts, 15)
      title = Thread.objects.get(pk=pk).title
      return render_to_response("forum/thread.html", add_csrf(request, posts=posts, pk=pk,
    title=title, media_url=MEDIA_URL))
  def add_csrf(request, ** kwargs):
      d = dict(user=request.user, ** kwargs)
      d.update(csrf(request))
      return d

  def mk_paginator(request, items, num_items):
      """Create and return a paginator."""
      paginator = Paginator(items, num_items)
      try: page = int(request.GET.get("page", '1'))
      except ValueError: page = 1

      try:
          items = paginator.page(page)
      except (InvalidPage, EmptyPage):
          items = paginator.page(paginator.num_pages)
      return items

csrf をインポートするモジュールがわからない

4

1 に答える 1

2

私はから答えを見つけましたdjango.core.context_processors import csrf:]

于 2013-02-17T12:30:59.577 に答える