Django 用类的方式处理POST GET

app.views.py

from django.views.generic.base import View

class LoginView(View):
    def get(self,request):
        return render(request, "login.html", {})
    def post(self,request):
        user_name = request.POST.get("username","")
        pass_word = request.POST.get("password","")
        user = authenticate(username=user_name,password=pass_word)
        if user is not None:
            login(request,user)
            return render(request,"index.html")
        else:
            return render(request,"login.html",{"msg":"用户名或密码错误"})


你可能感兴趣的:(django)