https://www.pythoneatstail.com/en/overview-all-articles/set-allauth-django-project/
1. base.py
pip3 install django-allauth
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',
...
)
INSTALLED_APPS
'django.contrib.auth',
'django.contrib.messages',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
SITE_ID = 1
2. urls.py
pet/urls.py
from django.urls import path
urlpatterns = [
...
path('accounts/', include('allauth.urls')),
...
]
3. HTML
{% extends 'account/base_card.html' %}
{% load i18n static %}
{% block title %}{% trans "Profile" %}{% endblock %}
{% block card-header %}
<h3>{% trans "Account profile" %}</h3>
{% endblock %}
{% block card-body %}
<div class="container">
<div class="row">
<div class="col border">
<small>{% trans "First name" %}:</small><br>
{{ request.user.first_name|default:'' }}
</div>
<div class="col border">
<small>{% trans "Last name" %}:</small><br>
{{ request.user.last_name|default:'' }}
</div>
</div>
</div>
{% endblock %}
만약에 first_name 하고 last_name이 없을 경우 default를 줘서 공백으로 처리한다.
4. models.py
def get_absolute_url(self):
return reverse('account_profile')
모델이 생성되었을 때, 바로 프로필 페이지로 넘어간다. account_profile은 profile page url의 name이다.
'Back-End > PythonEatsTail' 카테고리의 다른 글
06 Signup and password reset with allauth in Django (0) | 2021.12.09 |
---|---|
05 Git and local settings in Django (0) | 2021.12.08 |
04 Setting up validated login with allauth in Django (0) | 2021.12.08 |
02 Adding extra fields to a Django custom user model (0) | 2021.12.07 |
01 Wagtail with a custom user model (0) | 2021.12.07 |