django 회원가입, 로그인을 위해 django-rest-auth와 django-allauth를 설치해보자.
pip3 install django-rest-auth
pip3 install django-allauth
# 위 명령 안 내리면 에러 남
# 버전은 각 0.9.5, 0.42.0
그리고 이 링크를 기준으로 settings.py와 urls.py를 설정해준다.
이때 urls.py에서 url 대신 path를 써주는데,
url(r'^rest-auth/', include('rest_auth.urls'))
을
path('rest-auth/', include('rest_auth.urls')),
이런 형식으로 바꿔준다.
이후
(이건 이 단계에서 하면 안된다. 무조건 customizing 이후에 하기!!)
python manage.py migrate
# 결과: Apply all migrations: account, admin, auth, authtoken, contenttypes, posts, sessions, site
# settings.py에서 수정해주기, 안해주면 회원가입 때 에러 남. 위 링크에 해당하는 rest-auth 튜토리얼에 없음.
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
이건 이 단계에서 하면 안된다. 무조건 customizing 이후에 하기!!
# 아래와 같이 0.0.0.0을 해둔 이유는 aws ec2이기 때문에, 다른 컴퓨터에서도 접속해야 하기 때문이다.
python manage.py runserver 0.0.0.0:8000
을 해주면 아름답게 잘 된다.
++ 회원가입, 로그인이 잘 되는 지 확인을 위해 만든 유저 계정을 삭제하려면
superuser로 들어가서(접속주소:8000/admin에서) 삭제하면 되는데, 이 경우 아래와 같이 에러가 뜬다.
'allauth.socialaccount'
를 settings.py의 installed apps에 추가해주고
python manage.py migrate
를 해주고 다시 runserver를 돌려줘서 삭제하면 잘 된다.