Django의 session 로그인 및 등록

1396 단어
def register(request):
if request.method=='POST':
    name=request.POST.get('name')
    shop_name=request.POST.get('shop_name')
    password=request.POST.get('password')
    if not all([name,password]):
        error=' !'
        return render(request,'login.html',locals())
    else:
        user=User.objects.create(name=name,shop_name=shop_name,password=password)
        return redirect('/login/')
return render(request,'register.html')

def login(request):
if request.method=='POST':
    name=request.POST.get('name')
    password=request.POST.get('password')
    if not all([name,password]):
        error=' !'
        return render(request,'login.html',locals())
    else:
        user_name=User.objects.filter(name=name).first()
        if user_name:
            user=User.objects.filter(name=name,password=password).first()
            if user:
                request.session['user']=name
                return redirect('/show_user/')
            else:
                error=' '
                return render(request,'login.html',locals())
        else:
            error=' , '
            return render(request,'login.html',locals())
return render(request,'login.html')

좋은 웹페이지 즐겨찾기