管理站点:TemplateDoesNotExist at/admin/
问题描述
我正在关注 Django 的官方 Tutorial 2 但由于某种原因无法创建管理站点,尽管按照我的理解正确执行所有步骤.
I'm following Django's official Tutorial 2 but for some reason cannot create an admin site despite following all the steps correctly to my understanding.
这是我得到的错误:
TemplateDoesNotExist at /admin/
admin/login.html
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.3.1
Exception Type: TemplateDoesNotExist
Exception Value:
admin/login.html
Exception Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/loader.py in find_template, line 138
Python Executable: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.2
Python Path:
['/Users/jcugley/Documents/Programming/Python/Django/mysite',
'/Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
'/Library/Python/2.7/site-packages']
Server time: Tue, 24 Jan 2012 18:40:03 -0600
在我取消注释以下行(已注释)后发生错误:
The error occurs after I uncomment the following lines (commented):
### urls.py ###
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin # THIS LINE
admin.autodiscover() # THIS LINE
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)), # THIS LINE
)
如果我再次评论它们,它会消除错误.
If I comment them again it gets rid of the error.
我确实在 settings.py 的 INSTALLED_APPS 中有 django.contrib.admin
I do have django.contrib.admin
in my INSTALLED_APPS in settings.py
解决方案
由于它可以在其他人的机器上运行,并且由于您启用了应用程序目录加载器,因此在 INSTALLED_APPS
中启用了管理站点,那就是发现模板所需的一切(我的意思是,还能做什么?)-我只能假设您的 django 安装有问题.
Since it works on other people's machines, and since you have the app directories loader enabled, admin site enabled in INSTALLED_APPS
, and that's all it should take for templates to be discovered (I mean, what more can one do?) - I can only assume something is wrong with your django installation.
这将是开始使用 virtualenvs 和全新安装 django 以排除您的设置的好机会:
This would be a good chance to start using virtualenvs and a fresh install of django to rule out your settings:
启动终端,导航到您的项目目录(实际上并不重要...)
Fire up a terminal, navigate to your project directory (doesn't actually matter...)
pip install virtualenv # if you don't have it.
virtualenv --no-site-packages env
# this creates a virtual python environment that doesn't include system packages
source env/bin/activate
# this forces your bash session to use that environment
pip install django
# installs a fresh copy of django to your new environment
cd path_to_my_django_project
# now go to your site directory
python manager.py runserver
# visit admin site.
相关文章