본문 바로가기
프레임워크/Django

[Django] 1. 장고 유저 기능 Allauth 설정

by nahkim 2023. 1. 9.

Allauth 설정 방법

1. allauth 설치
bash

pip install django-allauth

 

2. settings.py 설정
루트 파일의 settings.py

INSTALLED_APPS += [
    "allauth",
    "allauth.account",
    "allauth.socialaccount",
    # include the providers you want to enable:
]

AUTHENTICATION_BACKENDS = [
    # Needed to login by username in Django admin, regardless of `allauth`
    "django.contrib.auth.backends.ModelBackend",
    # `allauth` specific authentication methods, such as login by e-mail
    "allauth.account.auth_backends.AuthenticationBackend",
]

SITE_ID = 1

 

3. urls.py 설정
루트 파일의 urls.py

from django.urls import path, include

urlpatterns = [
    path("", include("allauth.urls")),
]

allauth.urls를 맨 아래에 두는 것을 권장!
allauth 사이트에선 path('accounts/', include('allauth.urls')),로 나와있지만
나는 accounts를 사용하기 때문에 path를 변경함!

 

4. 데이터 베이스 테이블 생성
bash

python manage.py migrate

 

5. 확인하기
서버 실행

python manage.py runserver


설치가 잘 된건지 확인하려면 '/login/'에 접속해서 위와 같이 로그인 화면이 나오는지 확인!



allauth 홈페이지
https://django-allauth.readthedocs.io/en/latest/installation.html