1
NameError at /todos/accounts/register/
global name 'csrf' is not defined
Request Method: GET
Request URL: http://localhost:8000/todos/accounts/register/
Django Version: 1.10.5
Exception Type: NameError
Exception Value:
global name 'csrf' is not defined
Exception Location: /home/rahul/Desktop/apps/todolist/todos/views.py in register, line 37
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
장고 1.10에 정의되지 않은 : 현재 내 코드 전역 이름 'CSRF'을 보여주고있다 전역 이름 'CSRF는'views.py에 오류
from django.shortcuts import render from django.http import HttpResponse from .models import Todo from django.shortcuts import render_to_response from django.http import HttpResponseRedirect from django.contrib.auth.forms import UserCreationForm #from django.core.context_processors import csrf def index(request): todos = Todo.objects.all()[:10] context = { 'todos' : todos } return render(request, 'index.html', context) def details(request, id): todo = Todo.objects.get(id=id) context = { 'todo' : todo } return render(request, 'details.html', context) def register(request): if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/accounts/register/complete') else: form = UserCreationForm() token = {} token.update(csrf(request)) token['form'] = form return render_to_response('registration/registration_form.html', token) def registration_complete(request): return render_to_response('registration/registration_complete.html')
는를 정의되어 있지 않습니다. 이 오류를 극복하기 위해
의 django.core.context_processors에서 csrf을 가져 오는 경우
context_processors 모듈을 찾을 수 없다는 것보다이 표시됩니다. 도와주세요.
미리 감사드립니다.
감사합니다. 이게 내 문제를 해결했다. – KKlalala