현재 기본 모델은 AUTH_USER_MODEL = 'user.UserModel'
# user(app) > views.py > sign_up_view(request)
from django.shortcuts import render, redirect
from .models import UserModel
from django.http import HttpResponse
from django.contrib.auth import get_user_model # 추가
# 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:
exist_user = get_user_model().objects.filter(username=username) # 수정
if exist_user:
return render(request, 'user/signup.html')
else: # 사용자가 없다면
UserModel.objects.create_user(username=username, password=password, bio=bio) # 수정
return redirect('/sign-in')