我是 Django、Python 和这个网站的新手。我已经阅读了“如何使用 django 进行探戈”中的 Django 文档和教程,现在我遇到了障碍。我收到一个错误 No module names admin.sites.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}), )
设置.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
最佳答案
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')),
)
关于python - 没有名为 admin.sites.urls 的模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25453791/