-
django 기초 #002카테고리 없음 2022. 2. 12. 01:33
코드스니펫 붙여넣기하느라 정신 없었고 따라가느라 바빴다.
다만 두어번 더 보면 좀 나아질거 같은 느낌은 든다.
settings.py에서
'tweet'
'user'
추가
python manage.py makemigrations랑
python manage.py migrate 는 그래도 좀 익숙
from django.shortcuts import render, redirect from .models import UserModel from django.http import HttpResponse # Create your views here. def sign_up_view(request): if request.method == 'GET': return render(request, 'user/signup.html') elif request.method == 'POST': username = request.POST.get('username', None) password = request.POST.get('password', None) password2 = request.POST.get('password2', None) bio = request.POST.get('bio', None) if password != password2: return render(request, 'user/signup.html') else: new_user = UserModel() new_user.username = username new_user.password = password new_user.bio = bio new_user.save() return redirect('/sign-in') def sign_in_view(request): if request.method == 'POST': username = request.POST.get('username', None) password = request.POST.get('password', None) me = UserModel.objects.get(username = username) if me.password == password: request.session['user'] = me.username return HttpResponse("로그인 성공!") else: return redirect('/sign-in') elif request.method == 'GET': return render(request, 'user/signin.html')
이 내용은 다시 봐야겠다 ㅠ