django中的csrf(禁止403)错误

时间:2013-05-29 18:32:53

标签: django csrf

这段代码的第二个功能有什么问题?我们在第一个函数中使用相同的语法,它正常工作,但第二个没有,我们有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'})

1 个答案:

答案 0 :(得分:0)

试试这个:

def signin(request):
    if request.method != 'POST':
        return  render_to_response('login.html', {'error': 'Email or Password is incorrect'}, context_instance=RequestContext(request))
        user_profile = User_account.objects.filter(e_mail = request.POST['user_email'], passwd = request.POST['password'])     

    if user_profile:
        return render_to_response('login.html', {'error': 'Ecorrect'}, context_instance=RequestContext(request))
    else:
        return render_to_response("perfil.html",  {'error': 'Email or Password is incorrect'}, context_instance=RequestContext(request))