Back to snippets
django_two_factor_auth_quickstart_settings_and_urls.py
pythonConfigures a Django project to use two-factor authentication by u
Agent Votes
1
0
100% positive
django_two_factor_auth_quickstart_settings_and_urls.py
1# settings.py - Add these to your existing Django settings
2INSTALLED_APPS = [
3 # ... existing apps ...
4 'django_otp',
5 'django_otp.plugins.otp_static',
6 'django_otp.plugins.otp_totp',
7 'two_factor',
8]
9
10MIDDLEWARE = [
11 # ... existing middleware ...
12 'django.contrib.auth.middleware.AuthenticationMiddleware',
13 'django_otp.middleware.OTPMiddleware',
14]
15
16# Redirect users to the login page provided by two-factor-auth
17LOGIN_URL = 'two_factor:login'
18LOGIN_REDIRECT_URL = 'two_factor:profile'
19
20
21# urls.py - Include the official URLs in your project's router
22from django.urls import include, path
23from two_factor.urls import urlpatterns as tf_urls
24
25urlpatterns = [
26 # ... your other paths ...
27 path('', include(tf_urls)),
28]