简体   繁体   English

django中的csrf(forbidden 403)错误

[英]csrf(forbidden 403) error in django

what is problem with the second function of this code? 该代码的第二个功能有什么问题? we use the same syntax in the first function and it works correctly,but the second doesn't and we have csrf error...(forbidden 403) 我们在第一个函数中使用了相同的语法并且可以正常工作,但是第二个函数却没有,并且出现了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'})

Try this: 尝试这个:

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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM