Django - redirect to version with www

前端 未结 3 1929
温柔的废话
温柔的废话 2021-02-07 22:41

Is in Django a simple way to redirect everything from domain without www to version with it? I mean from http:// example.com to http:// www.example.com.

相关标签:
3条回答
  • 2021-02-07 23:01

    I have it. It is PREPEND_WWW in settings.

    https://docs.djangoproject.com/en/dev/ref/settings/?from=olddocs#prepend-www

    0 讨论(0)
  • 2021-02-07 23:03

    You can also skip prefix via proper DNS configuration.

    0 讨论(0)
  • 2021-02-07 23:11

    As docs say

    If PREPEND_WWW is True, URLs that lack a leading “www.” will be redirected to the same URL with a leading “www.”

    By default PREPEND_WWW is set to False. You can change that to True in settings.

    PREPEND_WWW = True
    

    To make this work, You have to include CommonMiddleware in Your middlewares

    MIDDLEWARE_CLASSES = (
        'django.middleware.common.CommonMiddleware',
    )
    
    0 讨论(0)
提交回复
热议问题