$ python manage.py startapp kakaoapi
$ pip install django-allauth
INSTALLED_APPS = [
'kakaoapi',
...
# allauth
'allauth',
'allauth.account',
'allauth.socialaccount',
# provider
'allauth.socialaccount.providers.kakao',
...
]
...
# 파일 제일 밑에 아래 코드 추가하기
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
]
SITE_ID = 1
LOGIN_REDIRECT_URL = '/' # 로그인 후 리디렉션할 페이지
ACCOUNT_LOGOUT_REDIRECT_URL ='/' # 로그아웃 후 리디렉션 할 페이지
ACCOUNT_LOGOUT_ON_GET = True # 로그아웃 버튼 클릭 시 자동 로그아웃
{% load socialaccount %} {% providers_media_js %}
<h1>Hello World</h1>
<a href="/accounts/signup">회원가입</a>
<br />
{% if user.is_authenticated %}
<a href="/accounts/logout">로그아웃</a>
<br />
{{user.username}}님이 로그인 중 {% else %}
<a href="{% provider_login_url 'kakao' %}">카카오 로그인</a>
로그인하세요.
{% endif %}
from django.shortcuts import render
def home(request):
return render(request, 'home.html')
from django.contrib import admin
from django.urls import path, include
import kakaoapi.views
...
urlpatterns = [
...
path('accounts/', include('allauth.urls')),
path('', kakaoapi.views.home, name='home'),
...
]
python manage.py createsuperuser
Username (leave blank to use 'pinco'): admin
Email address: admin@naver.com
Password: admin
Password (again): admin
Superuser created successfully.
$ python manage.py migrate
내 애플리케이션 > 애플리케이션 추가하기 > 정보 입력 > 저장
앱 설정 > 플랫폼 메뉴 > Web > Web 플랫폼 설정
3번에서 '등록하러 가기' 버튼을 눌러도 되고, 아래 경로로 들어가도 무방하다.
제품설정 > 카카오 로그인
http://localhost:8000/
http://localhost:8000/accounts/kakao/login/callback/
$ python manage.py runserver
https://developers.kakao.com/docs/latest/ko/kakaologin/trouble-shooting
https://docs.kakaoi.ai/kakao_i_agent/instance/application/
https://django-allauth.readthedocs.io/en/latest/installation.html