General Settings


Whether the Django admin is patched to use the default login view.


The admin currently does not enforce one-time passwords being set for admin users.


Which gateway to use for making phone calls. Should be set to a module or object providing a make_call method. Currently two gateways are bundled:

  • 'two_factor.gateways.twilio.gateway.Twilio' for making real phone calls using Twilio.
  • 'two_factor.gateways.fake.Fake' for development, recording tokens to the default logger.

Which gateway to use for sending text messages. Should be set to a module or object providing a send_sms method. Currently two gateways are bundled:

  • 'two_factor.gateways.twilio.gateway.Twilio' for sending real text messages using Twilio.
  • 'two_factor.gateways.fake.Fake' for development, recording tokens to the default logger.

Should point to the login view provided by this application as described in setup. This login view handles password authentication followed by a one-time password exchange if enabled for that account.

See also LOGIN_URL.


This application provides a basic page for managing one’s account. This view is entirely optional and could be implemented in a custom view.



The default generator for the QR code images is set to SVG. This does not require any further dependencies, however it does not work on IE8 and below. If you have PIL, Pillow or pyimaging installed you may wish to use PNG images instead.

  • 'qrcode.image.pil.PilImage' may be used for PIL/Pillow
  • 'qrcode.image.pure.PymagingImage' may be used for pyimaging

For more QR factories that are available see python-qrcode.


The number of digits to use for TOTP tokens, can be set to 6 or 8. This setting will be used for tokens delivered by phone call or text message and newly configured token generators. Existing token generator devices will not be affected.


The Google Authenticator app does not support 8 digit codes (see the upstream ticket). Don’t set this option to 8 unless all of your users use a 8 digit compatible token generator app.

The default region for parsing phone numbers. If your application’s primary audience is a certain country, setting the region to that country allows entering phone numbers without that country’s country code.

Twilio Gateway

To use the Twilio gateway, you need first to install the Twilio client:

pip install twilio

Next, you also need to include the Twilio urlpatterns. As these urlpatterns are all defined using a single Django namespace, these should be joined with the base urlpatterns, like so:

from two_factor.urls import urlpatterns as tf_urls
from two_factor.gateways.twilio.urls import urlpatterns as tf_twilio_urls

urlpatterns = [
    url(r'', include(tf_urls + tf_twilio_urls, 'two_factor')),

Additionally, you need to enable the``ThreadLocals`` middleware:


    # Always include for two-factor auth

    # Include for twilio gateway
class two_factor.gateways.twilio.gateway.Twilio

Gateway for sending text messages and making phone calls using Twilio.

All you need is your Twilio Account SID and Token, as shown in your Twilio account dashboard.

Should be set to your account’s SID.
Should be set to your account’s authorization token.
Should be set to a verified phone number. Twilio differentiates between numbers verified for making phone calls and sending text messages.

Fake Gateway

class two_factor.gateways.fake.Fake

Prints the tokens to the logger. You will have to set the message level of the two_factor logger to INFO for them to appear in the console. Useful for local development. You should configure your logging like this:

    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
    'loggers': {
        'two_factor': {
            'handlers': ['console'],
            'level': 'INFO',