我对Django tutorial的这一部分感到困惑。它说类似于将整个admin模板复制到dbe/templates,但是完整路径应该是什么,我应该创建什么文件夹?
我运行的是Mac,我的待办事项应用程序位于/Users/hobbes3/Sites/mysite/todo/,我的完整Django路径是/usr/local/lib/python2.7/site-packges/django/。
我还将我的模板放在了/Users/hobbes3/Sites/myDjango/templates。在这个文件夹中,我有admin/base_site.html和polls/detail.html、polls/index.html和polls/results.html。投票应用程序是从official Django tutorial创建的。我的投票应用程序运行得很好。
当我使用python manage.py runserver运行服务器并转到http://127.0.0.1:8000/admin/时,我得到的错误是
ImportError at /admin/
No module named dbe.todo.models
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.3.1
Exception Type: ImportError
Exception Value:
No module named dbe.todo.models
Exception Location: /Users/hobbes3/Sites/mysite/todo/admin.py in <module>, line 1
Python Executable: /usr/local/bin/python
Python Version: 2.7.2
Python Path:
['/Users/hobbes3/Sites/mysite',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.4-x86_64.egg',
'/usr/local/Cellar/python/2.7.2/lib/python27.zip',
'/usr/local/Cellar/python/2.7.2/lib/python2.7',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/plat-darwin',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/plat-mac',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/lib-tk',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/lib-old',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/lib-dynload',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
Server time: Fri, 24 Feb 2012 05:09:28 -0600发布于 2012-02-24 19:37:40
对于初学者,您应该遵循官方教程:https://docs.djangoproject.com/en/dev/intro/tutorial01/
你正在学习的教程看起来很糟糕(对不起:/)
我怀疑dbe就是这个家伙的项目名称。当他出现时:
cp -r django/contrib/admin/templates/admin/ dbe/templates/看起来他把django和项目放在了同一级别。所以他的dbe ==你的网站。
无论如何,没有必要在应用程序模块前加上项目模块名称,这是荒谬的--在应用程序中硬编码项目名称。这完全违背了可重用应用程序的目的。运行以下命令:
find /path/to/your/project -type f | xargs sed -i -e s/dbe.//g此命令将删除'dbe.‘’。从你的代码中的任何地方。这篇教程代码太可怕了,我想知道你为什么还要费心去读它……
https://stackoverflow.com/questions/9429910
复制相似问题