2013-02-17 2 views
1

이 자습서를 사용하여 포럼을 만들고 있습니다. http://lightbird.net/dbe/forum1.htmlDjango 오류 글로벌 이름 'csrf'가 정의되지 않았습니다.

이 오류가 표시되며 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 

내가

답변

2

내가 django.core.context_processors import csrf에서 답을 찾을 CSRF 가져올 어떤 모듈 모른다 :]

관련 문제