pip install django-allauth
python
INSTALLED_APPS = [
...
'django.contrib.sites',
'allauth',
'allauth.account',
...
]
python
AUTHENTICATION_BACKENDS = [
...
'allauth.account.auth_backends.AuthenticationBackend',
...
]
python
SITE_ID = 1
python
from django.urls import include, path
urlpatterns = [
...
path('accounts/', include('allauth.urls')),
...
]
python
from django.contrib.auth.models import AbstractUser
from django.db import models
class CustomUser(AbstractUser):
some_field = models.CharField(max_length=100)
...
python
AUTH_USER_MODEL = 'your_app.CustomUser'
python manage.py makemigrations
python manage.py migrate
python
# views.py
from allauth.account.views import SignupView
class CustomSignupView(SignupView):
template_name = 'account/signup.html'
html
<!-- templates/account/signup.html -->
<form method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{{ form.as_p }}
</form>
python
# urls.py
urlpatterns = [
...
path('accounts/signup/', CustomSignupView.as_view(), name='account_signup'),
...
]
python
# views.py
from django.contrib.auth.views import LoginView
class CustomLoginView(LoginView):
template_name = 'account/login.html'
html
<!-- templates/account/login.html -->
<form method="post" action="{% url 'account_login' %}">
{% csrf_token %}
{{ form.as_p }}
</form>
python
# urls.py
urlpatterns = [
...
path('accounts/login/', CustomLoginView.as_view(), name='account_login'),
...
]
python
# settings.py
SOCIALACCOUNT_QUERY_EMAIL = True
SOCIALACCOUNT_PROVIDERS = {
'openid': {
},
'google': {
'APP': {
'client_id': 'your_client_id',
'secret': 'your_secret_key',
'key': ''
}
}
}
html
<!-- templates/account/socialaccount_connections.html -->
{% include 'includes/snippets/provider_login.html' %}