Welcome to our Django-allauth tutorial! In this comprehensive guide, we'll walk you through setting up user authentication for your Django projects. By the end, you'll have a solid understanding of how to manage user accounts, login, logout, and more! π
To follow along, make sure you have Django installed. If not, check out our Django Tutorial first!
pip install django-allauthAdd 'allauth', 'allauth.account', and 'allauth.socialaccount' to your INSTALLED_APPS in settings.py.
INSTALLED_APPS = [
# ...
'allauth',
'allauth.account',
'allauth.socialaccount',
# ...
]In your project's urls.py, include the following:
from django.urls import path
from allauth.urls import socialaccount_urlpatterns
urlpatterns = [
# ...
path('accounts/', include('allauth.urls')),
path('accounts/social/', socialaccount_urlpatterns, name='socialaccount_urls'),
# ...
]Django-allauth works with Django's built-in User model and third-party user models like Django-Guardian. If you're using a custom user model, make sure it extends AbstractUser or AbstractBaseUser.
Now, navigate to your browser and visit http://localhost:8000/accounts/signup/. You can register a new user!
For login and logout, visit http://localhost:8000/accounts/login/ and http://localhost:8000/accounts/logout/, respectively.
Django-allauth supports third-party login providers like Google, Facebook, and GitHub. To enable, go to settings.py and add the desired providers to SOCIALACCOUNT_PROVIDERS.
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'profile',
'email',
],
'AUTH_PARAMS': {
'access_type': 'online',
},
}
# Add more providers as needed
}Django-allauth offers many more features like email verification, passwordless login, account activation, and more. Explore the documentation for a comprehensive guide!
What should you add to your `INSTALLED_APPS` to use Django-allauth?
Stay tuned for more in-depth lessons on Django-allauth! Happy coding, and remember: if you ever get stuck, feel free to ask for help. π€
Next up: Django-allauth Advanced Topics π