简体   繁体   English

ImportError at / No模块名为urls

[英]ImportError at / No module named urls

I've created a basic Django installation under a virtualenv, started a project and enabled the admin and admin docs. 我在virtualenv下创建了一个基本的Django安装,启动了一个项目并启用了admin和admin文档。 When I run the server I get the following error: 当我运行服务器时,我收到以下错误:

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

My urls.py file looks like: 我的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')),
)

And my settings.py file's Installed Apps section looks like: 我的settings.py文件的Installed Apps部分如下所示:

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',
)

I've looked through many other posts here and elsewhere but can't find a resolution. 我在这里和其他地方看了很多其他帖子,但找不到解决方案。 Any idea what's going on? 知道发生了什么事吗?

In your settings.py file, make sure the ROOT_URLCONF is correct. 在settings.py文件中,确保ROOT_URLCONF正确无误。

It should look something like: 它应该看起来像:

ROOT_URLCONF = '<INSERT PROJECT NAME>.urls'

Judging by what you've provided, you might want to make sure it looks like: 根据您提供的内容判断,您可能希望确保它看起来像:

ROOT_URLCONF = 'projectname.urls'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM