AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'
Asked Answered
C

5

36

Following on from my last question Error: No module named psycopg2.extensions, I have updated my mac OS to Mountain Lion and installed Xcode. I have also installed psycopg2 using 'sudo port install py27-psycopg2'. I am now trying to run 'python manage.py runserver' but am receiving this error

AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'

Any help on how to fix this and get my localhost running?

Catamnesis answered 11/10, 2012 at 12:10 Comment(0)
J
20

From django docs:

A Django settings file contains all the configuration of your Django installation. When you use Django, you have to tell it which settings you're using. Do this by using an environment variable, DJANGO_SETTINGS_MODULE.

The value of DJANGO_SETTINGS_MODULE should be in Python path syntax, e.g. mysite.settings. Note that the settings module should be on the Python import search path.

And

ROOT_URLCONF

Default: Not defined

A string representing the full Python import path to your root URLconf. For example: "mydjangoapps.urls". Can be overridden on a per-request basis by setting the attribute urlconf on the incoming HttpRequest object. See How Django processes a request for details.

Jerkin answered 11/10, 2012 at 12:14 Comment(5)
Thanks for your answer. I have already set DJANGO_SETTINGS_MODULE to mysite.settings and followed the docs and it is still causing the error. That's why I'm not sure what is going wrong.Catamnesis
Most likely, there is no definition of ROOT_URLCONF in your settings file. This settings is required and is must point to a file, which defines the URLs of your application.Jerkin
My settings file reads ROOT_URLCONF = 'mysite.urls'. Is that correct? Sorry if this is a really simple issue - it's my first experience with this. I believe I have everything set up correctly but I am still seeing the error I posted above and when I go to my localhost there's an error saying 'A server error occurred. Please contact the administrator.' Thanks again for your help.Catamnesis
Thank you... I was looking how to dynamically configure the urls.py depending on the domain. This works well to set the urlconf in middleware... thanks a bunch.Diatomite
+1, reading your answer, i recalled that i forgot to run buildout after renaming my settings.py)Became
C
7

If you are using multiple settings files, be sure to import the base settings in all the other settings files. This was how I got this error.

Clergy answered 12/5, 2021 at 17:1 Comment(1)
Can you give example please.Formative
N
5

If you're working on a Django project, the root of your project(ROOT_URLCONF= variable) isn't defined in your settings.py file, or at least it isn't defined properly.

If you don't have a settings.py file, this block of code should fix the issue:

from django.conf import settings

settings.configure(
# ...
    ROOT_URLCONF=__name__,
# ...
    ),
)

What that does is specify the root of your project runserver knows where to find your project.

If do have a settings.py file, then find that variable and add __name__ to it.

Nert answered 21/10, 2018 at 10:33 Comment(2)
when I use the block of code, I get RuntimeError: Settings already configured.Barnabe
Thanks for the reply. Unfortunately, it didn't work. The error now is as follows: ``` django.core.exceptions.ImproperlyConfigured: The included URLconf 'eMenue.settings' does not appear to have any patterns in it. If you see the 'urlpatterns' variable with valid patterns in the file then the issue is probably caused by a circular import. ``` My original value in settings was: ROOT_URLCONF = 'eMenue.urls'Formative
C
2

Importing project settings directly can cause this to happen:

from config import settings  # bad

from django.conf import settings # good
Certified answered 20/4, 2023 at 3:3 Comment(0)
D
1

A bit late answer but hope it helps someone. This happens when you have multiple settings.py files.

  1. First check if ROOT_URLCONF = "[name].urls" is defined in your settings.py

  2. If it is defined, use shell to check if it returns the value. python manage.py shell from django.conf import settings print(settings.ROOT_URLCONF)

  3. If it returns "[name].urls" as it should, check wsgi.py file. I had multiple settings.py file like base.py local.py production.py and i did not set it to production.py which caused problem

Instead of os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings')

do this os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings.production')

Deirdredeism answered 18/1 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.