编程语言
首页 > 编程语言> > python-没有名为admin.sites.urls的模块

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

作者:互联网

我是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

解决方法:

塞比约恩是对的.您的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')),
)

标签:python-2-7,django-admin,python,django,django-models
来源: https://codeday.me/bug/20191029/1958318.html