Take the 2-minute tour ×

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?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Never user from settings import ... or import settings. This will always only import your settings module, but not the whole Django settings.

Use from django.conf import settings instead 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_TYPE via settings.DEFAULT_CONTENT_TYPE.

share|improve this answer
Yes, as mentioned in the documentation. –  rm. Aug 17 '11 at 3:29
There they go hiding it in the documentation. How do they expect anyone to find it there? –  monkut Aug 17 '11 at 6:35

settings is relative to your project, so it'll try to import DEFAULT_CONTENT_TYPE from your settings file. If you want to use Django's built-in DEFAULT_CONTENT_TYPE setting, you'd have to include it from their libraries (sorry, don't have Django installed on this machine, otherwise I'd look up the file that it's defined in).

Something like this: from django.some.settings.file import DEFAULT_CONTENT_TYPE

You should be able to find it by just grep'ing through your Django lib dir.

share|improve this answer

Your Answer


