没有名为admin.sites.urls的模块

时间:2014-08-22 18:55:53

标签: python django python-2.7 django-models django-admin

我是Django,Python和本网站的新手。我已经阅读了Django文档和“如何与django探戈,现在我遇到了障碍。我得到一个错误没有模块名称admin.sites.urls,不知道我现在需要做什么。”

urls.py:

from django.conf import settings
from django.conf.urls import patterns, include, url
from rango import views
from django.contrib import admin, admindocs
admin.autodiscover()

urlpatterns = patterns('',

    url(r'^$', 'rango.views.index', name='index'),
    url(r'^$', 'rango.views.about', name ='about'),
    url(r'^rango/', include('RangoTango.urls')),
    url(r'^admin/', include(admin.sites.urls)),
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
) 

if settings.DEBUG:
    urlpatterns += patterns(
    'django.views.static',
    (r'media/(?P<path>.*)',
    'serve',
    {'document_root': settings.MEDIA_ROOT}), ) 

Settings.py:

INSTALLED_APPS = (
     'django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'django.contrib.admin',
     'django.contrib.admindocs',
     'rango',

 )

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'RangoTango.urls'

WSGI_APPLICATION = 'RangoTango.wsgi.application'

错误:

ImportError at /admin

No module named admin.sites.urls

Request Method:     GET
Request URL:    127.0.0.1:8000/admin
Django Version:     1.6.5
Exception Type:     ImportError
Exception Value:    

No module named admin.sites.urls

Exception Location:     /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py in import_module, line 40
Python Executable:  /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version:     2.7.6
Python Path:    

[
Server time:    Fri, 22 Aug 2014 18:44:18 +0000

1 个答案:

答案 0 :(得分:4)

thebjorn是对的。你的urls.py看起来应该更像这样。

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'tango.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),  ## Here's the typo
    url(r'^rango/', include('rango.urls')),
)