完整的错误消息是:
AttributeError on running Django app on apache as localhost -- 'Adminsite' object has no attribute 'root'
Environment: Request Method: GET Request URL: http://localhost:8000/ Django Version: 1.3 Python Version: 2.6.5 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'esp.datatree', 'esp.users', 'esp.membership', 'esp.miniblog', 'esp.web', 'esp.program', 'esp.program.modules', 'esp.dbmail', 'esp.cal', 'esp.lib', 'esp.setup', 'esp.qsd', 'esp.qsdmedia', 'esp.resources', 'esp.gen_media', 'esp.dblog', 'esp.membership', 'esp.queue', 'esp.survey', 'esp.accounting_core', 'esp.accounting_docs', 'esp.shortterm', 'esp.utils', 'esp.cache', 'esp.cache_loader', 'esp.tagdict', 'django_extensions', 'south', 'sslauth'] Installed Middleware: ['esp.middleware.threadlocalrequest.ThreadLocals', 'esp.middleware.FixIEMiddleware', 'esp.middleware.ESPErrorMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'esp.middleware.espauthmiddleware.ESPAuthMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.doc.XViewMiddleware', 'sslauth.middleware.SSLAuthMiddleware', 'django.middleware.gzip.GZipMiddleware', 'esp.middleware.PrettyErrorEmailMiddleware', 'esp.middleware.StripWhitespaceMiddleware', 'django.middleware.transaction.TransactionMiddleware', 'esp.datatree.middleware.DataTreeLockMiddleware'] Traceback: File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/handlers/base.py" in get_response 101. request.path_info) File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/urlresolvers.py" in resolve 250. for pattern in self.url_patterns: File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/urlresolvers.py" in _get_url_patterns 279. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/urlresolvers.py" in _get_urlconf_module 274. self._urlconf_module = import_module(self.urlconf_name) File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/utils/importlib.py" in import_module 35. __import__(name) File "/home/lakshay/mysite/esp/esp/esp/../esp/urls.py" in 58. (r'^admin/(.*)', admin.site.root), Exception Type: AttributeError at / Exception Value: 'AdminSite' object has no attribute 'root'
编辑以回复Aldarund:
是的,我确实更正了管理员的网址,但现在却出现了数据库错误。可能是什么问题呢?这是追溯:
Environment: Request Method: GET Request URL: http://127.0.0.1:8000/ Traceback: File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/core/handlers/base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "/home/lakshay/mysite/esp/esp/esp/../esp/web/views/main.py" in home 79. nav_category, created = NavBarCategory.objects.get_or_create(name='home') File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/db/models/manager.py" in get_or_create 135. return self.get_query_set().get_or_create(**kwargs) File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/db/models/query.py" in get_or_create 378. return self.get(**lookup), False File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/db/models/query.py" in get 344. num = len(clone) File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/db/models/query.py" in __len__ 82. self._result_cache = list(self.iterator()) File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/db/models/query.py" in iterator 273. for row in compiler.results_iter(): File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/db/models/sql/compiler.py" in results_iter 680. for rows in self.execute_sql(MULTI): File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/db/models/sql/compiler.py" in execute_sql 735. cursor.execute(sql, params) File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/db/backends/util.py" in execute 34. return self.cursor.execute(sql, params) File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/django/db/backends/postgresql_psycopg2/base.py" in execute 44. return self.cursor.execute(query, args) Exception Type: DatabaseError at / Exception Value: relation "web_navbarcategory" does not exist LINE 1: ...me", "web_navbarcategory"."long_explanation" FROM "web_navba... ^
答案 0 :(得分:57)
您的管理员网址应为:
url(r'^admin/', include(admin.site.urls))
不是(r'^admin/(.*)', admin.site.root)
- 它适用于Django 1.0。对于Django 1.3,它不起作用。
答案 1 :(得分:2)
我遇到的另一个可能的问题是,在settings.py文件中没有正确配置admin。有此问题的任何人都希望检查他们安装的应用是否包含django.contrib.admin。有关详细信息,请参阅https://docs.djangoproject.com/en/1.3/faq/admin/。