I must be missing something.
I’m trying to import DEFAULT_CONTENT_TYPE from the settings file.
I don’t define it specifically in my settings.py file, but I was assuming that the default would be available.
When I add this variable to my settings.py it works fine, but when it’s not there and I try to import I get an ImportError when using the development server via the runserver command:
from settings import DEFAULT_CONTENT_TYPE
ImportError: cannot import name DEFAULT_CONTENT_TYPE
Shouldn’t I be able to do this without having to add it to my settings.py file?
Never user
from settings import ...orimport settings. This will always only import your settings module, but not the whole Django settings.Use
from django.conf import settingsinstead in all your Django projects. This is using the Django Settings class which is a wrapper around all Django defined settings and your project settings from your settings file.So for your example you would access
DEFAULT_CONTENT_TYPEviasettings.DEFAULT_CONTENT_TYPE.