Course DRF level 3
- install django-rest-auth
- install django-allauth
- api-auth/ from rest_framework.urls are necessary for browsable API
- rest-auth/ from rest_auth.urls are ready for REST API
# modification in settings.py
INSTALLED_APPS = [
...,
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
]
}
urlpatterns = [
...,
url('rest-auth/', include('rest_auth.urls'))
url('api-auth/', include('rest_framework.urls'))
]
INSTALLED_APPS = (
...,
'django.contrib.sites',
'allauth',
'allauth.account',
'rest_auth.registration',
)
SITE_ID = 1
urlpatterns = [
...,
path('api/rest-auth/registration/', include('rest_auth.registration.urls')),
]
# signals.py in app
@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
class ProfilesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'profiles'
def ready(self) -> None:
import profiles.signals