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

微笑、不失礼 提交于 2019-12-18 05:37:46

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12839213/attributeerror-settings-object-has-no-attribute-root-urlconf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!