我跟随Django教程,我已经到了第4部分。但是当我回去查看我的管理页面时,它神秘地再也没有工作了。所以我搞砸了一点,想出了这个。
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/(.*)', admin.site.root),
#(r'^polls/', include('mysite.polls.urls')),
)
现在我可以进入我的管理页面,但如果我取消注释我的视图的网址(我在mysite子文件夹中有另一个urls.py,管理员无法工作。它会返回以下错误。
Request Method: GET
Request URL: http://192.168.0.5:9000/admin/
Exception Type: TemplateSyntaxError
Exception Value:
Caught an exception while rendering: Tried vote in module mysite.polls.views. Error was: 'module' object has no attribute 'vote'
Original Traceback (most recent call last):
File "/usr/local/lib/python2.5/site-packages/django/template/debug.py", line 71, in render_node
result = node.render(context)
File "/usr/local/lib/python2.5/site-packages/django/template/defaulttags.py", line 373, in render
url = reverse(self.view_name, args=args, kwargs=kwargs)
File "/usr/local/lib/python2.5/site-packages/django/core/urlresolvers.py", line 254, in reverse
*args, **kwargs)))
File "/usr/local/lib/python2.5/site-packages/django/core/urlresolvers.py", line 227, in reverse
possibilities = self.reverse_dict.getlist(lookup_view)
File "/usr/local/lib/python2.5/site-packages/django/core/urlresolvers.py", line 161, in _get_reverse_dict
for name in pattern.reverse_dict:
File "/usr/local/lib/python2.5/site-packages/django/core/urlresolvers.py", line 169, in _get_reverse_dict
self._reverse_dict.appendlist(pattern.callback, (bits, p_pattern))
File "/usr/local/lib/python2.5/site-packages/django/core/urlresolvers.py", line 136, in _get_callback
raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))
ViewDoesNotExist: Tried vote in module mysite.polls.views. Error was: 'module' object has no attribute 'vote'
Exception Location: /usr/local/lib/python2.5/site-packages/django/template/debug.py in render_node, line 81
Python Executable: /usr/bin/python
Python Version: 2.5.1
Python Path: ['/local/Programming/django/mysite', '/usr/lib/python2.5/site-packages/docutils-0.5-py2.5.egg', '/usr/lib/python2.5/site-packages/Pygments-1.0-py2.5.egg', '/usr/lib/python2.5/site-packages/pytz-2008i-py2.5.egg', '/usr/lib/python2.5/site-packages/Genshi-0.6dev_r999-py2.5-linux-i686.egg', '/usr/lib/python2.5/site-packages/Trac-0.11.3-py2.5.egg', '/usr/local/lib/python2.5/site-packages/setuptools-0.6c8-py2.5.egg', '/usr/local/lib/python2.5/site-packages/numpy-1.3.0-py2.5-linux-i686.egg', '/usr/lib/python25.zip', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages/Numeric', '/usr/lib/python2.5/site-packages/PIL', '/usr/lib/python2.5/site-packages/gtk-2.0', '/usr/local/lib/python2.5/site-packages']
Server time: Sun, 24 May 2009 19:59:08 -0500
所有我的观点在admin url注释掉的情况下运行良好。没有错误。
我正在运行Django 1.0.2 final。
感谢人们给予的任何帮助。
标记
答案 0 :(得分:1)
检查mysite.polls.urls。看来你在urls.py文件中有一行引用了一个名为vote的视图函数,该函数在mysite.polls.views中不存在。