我在virtualenv下创建了一个基本的Django安装,启动了一个项目并启用了admin和admin文档。当我运行服务器时,我收到以下错误:
Request URL: http://127.0.0.1:8000/
Django Version: 1.4.1
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/Users/farneman/Projects/project/project_env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/Users/farneman/Projects/project/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
298. for pattern in self.url_patterns:
File "/Users/farneman/Projects/project/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
328. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/farneman/Projects/project/project_env/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
323. self._urlconf_module = import_module(self.urlconf_name)
File "/Users/farneman/Projects/project/project_env/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
Exception Type: ImportError at /
Exception Value: No module named urls
我的urls.py文件如下:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'projectname.views.home', name='home'),
# url(r'^projectname/', include('projectname.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include('admin.site.urls')),
)
我的settings.py文件的已安装应用程序部分如下所示:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
)
我在这里和其他地方查看了很多其他帖子,但找不到解决方案。知道发生了什么事吗?
答案 0 :(得分:6)
在settings.py文件中,确保ROOT_URLCONF正确无误。
它应该类似于:
ROOT_URLCONF = '<INSERT PROJECT NAME>.urls'
根据您提供的内容判断,您可能需要确保它看起来像:
ROOT_URLCONF = 'projectname.urls'