'AdminSite' object has no attribute 'root'

我只是一个虾纸丫 提交于 2019-12-11 05:03:03

问题


    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'

The possible duplicate is How to correct this error: "'Adminsite' object has no attribute 'root'" .

where it is mentioned Your url for admin should be:

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

not (r'^admin/(.*)', admin.site.root) - it's for Django 1.0. For Django 1.3 it wouldn't work.

then I got this error

NameError at / name 'include' is not defined

    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

I am using Django Version 1.3.1.


回答1:


It seams that you forgot the from django.conf.urls.defaults import * or from django.conf.urls.defaults import include in your urls.py.




回答2:


Do you have this

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

in your urls.py?




回答3:


You probably haven't imported it:

from django.conf.urls.defaults import include

In general, when it says that something is not defined, it means that the compiler can't resolve something. This is usually caused by missing import statements or spelling errors.



来源:https://stackoverflow.com/questions/14567744/adminsite-object-has-no-attribute-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!