[Django]-How to pass a variable from settings.py to a view?

65👍

✅

Use from django.conf import settings but mind that settings is not a module. The documentation clearly explains that and your use case.

31👍

from django.conf import settings as conf_settings
project_path = conf_settings.PROJECT_PATH

6👍

  1. in settings.py add

    DOMAIN = "example.com"
    
  2. views.py

    from django.conf import settings
    
    DOMAIN = settings.DOMAIN
    
  3. lets try to output it:

    print(DOMAIN)
    
    print(type(DOMAIN))
    
  4. output will be:

    example.com
    
    <class 'str'>
    

Leave a comment