'AdminSite'对象没有属性'root'

时间:2013-01-28 17:31:31

标签: python django django-admin python-module django-errors

    Environment:


Request Method: GET
Request URL: http://54.235.168.5/mds/

Django Version: 1.3.1
Python Version: 2.7.3
Installed Applications:
['sana.mrs',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'sana.mrs.util.LoggingMiddleware')


Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  250.             for pattern in self.url_patterns:
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_url_patterns
  279.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_urlconf_module
  274.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/opt/sana/urls.py" in <module>
  131.     (r'^admin/(.*)', admin.site.root),

Exception Type: AttributeError at /
Exception Value: 'AdminSite' object has no attribute 'root'

可能的重复是How to correct this error: "'Adminsite' object has no attribute 'root'"

提到的地方 您的管理员网址应为:

url(r'^admin/', include(admin.site.urls))

不是(r'^admin/(.*)', admin.site.root) - 它适用于Django 1.0。对于Django 1.3,它不起作用。

然后我收到了这个错误

/的NameError 名称'include'未定义

    Environment:

Request Method: GET
Request URL: http://54.235.168.5/mds/

Django Version: 1.3.1
Python Version: 2.7.3
Installed Applications:
['sana.mrs',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'sana.mrs.util.LoggingMiddleware')


Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  250.             for pattern in self.url_patterns:
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_url_patterns
  279.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_urlconf_module
  274.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/opt/sana/urls.py" in <module>
  132.  url(r'^admin/', include(admin.site.urls))

Exception Type: NameError at /
Exception Value: name 'include' is not defined

我正在使用Django版本1.3.1。

3 个答案:

答案 0 :(得分:2)

你有这个吗?

from django.conf.urls.defaults import patterns, include, url

urls.py

答案 1 :(得分:1)

您忘记了urls.py中的from django.conf.urls.defaults import *from django.conf.urls.defaults import include

答案 2 :(得分:1)

您可能没有导入它:

from django.conf.urls.defaults import include

一般来说,当它说某事is not defined时,就意味着编译器无法解决某些问题。这通常是由于缺少导入语句或拼写错误引起的。