【发布时间】:2013-05-25 03:44:26
【问题描述】:
这段代码的第二个函数有什么问题?我们在第一个函数中使用相同的语法,它可以正常工作,但第二个没有,我们有 csrf 错误...(禁止 403)
from User.models import User_account
from django.http import HttpResponse
from django.core.context_processors import csrf
from django.shortcuts import render_to_response, render
def get_info(request):
if request.method == 'POST':
if request.POST['passwd']!=request.POST['cpasswd']:
return render(request,'signup.html',{'error':'The confirmed password does not match the first one'})
new_user = User_account.objects.create(first_name=request.POST['first_name'],last_name=request.POST['last_name'],e_mail=request.POST['e_mail'],passwd=request.POST['passwd'])
new_user.save()
return HttpResponse("your account was built")
def signin(request):
if request.method != 'POST':
return render(request, 'login.html', {'error': 'Email or Password is incorrect'})
user_profile = User_account.objects.filter(e_mail = request.POST['user_email'], passwd = request.POST['password'])
if user_profile:
return render(request, 'login.html', {'error': 'Ecorrect'})
else:
return render(request, 'login.html', {'error': 'Email or Password is incorrect'})
【问题讨论】:
-
模板中有csrf标签吗?
-
是的,我们拥有它并将其用于第一个功能,它可以工作!
-
您是否使用 AJAX 发送表单?
-
不! -------------------------------------------------- ----
-
你能分享你的模板吗?第一个函数返回到 signup.html,第二个函数返回到 login.html(为了清楚起见,我想我们需要看看它们里面有什么)