所以现在我还在Django教程第3部分:
http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03
尝试使用教程
提供的这段代码设置urls.pyfrom django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^polls/$', 'mysite.polls.views.index'),
(r'^polls/(?P<poll_id>\d+)/$', 'mysite.polls.views.detail'),
(r'^polls/(?P<poll_id>\d+)/results/$', 'mysite.polls.views.results'),
(r'^polls/(?P<poll_id>\d+)/vote/$', 'mysite.polls.views.vote'),
(r'^admin/', include(admin.site.urls)),
)
如果我使用此代码更改了我的默认urls.py(其中没有任何内容),则会显示127.0.0.1:8000/polls/,但出于某种原因127.0.0.1:8000/admin不再存在并给我以下错误:
异常类型:TemplateSyntaxError 异常值:渲染时捕获异常:在模块mysite.polls.views中尝试投票。错误是:'module'对象没有属性'vote'
And this (Error line 30):
Caught an exception while rendering: Tried vote in module mysite.polls.views. Error was: 'module' object has no attribute 'vote'
20 <!-- Header -->
21 <div id="header">
22 <div id="branding">
23 {% block branding %}{% endblock %}
24 </div>
25 {% if user.is_authenticated and user.is_staff %}
26 <div id="user-tools">
27 {% trans 'Welcome,' %}
28 <strong>{% firstof user.first_name user.username %}</strong>.
29 {% block userlinks %}
**30 {% url django-admindocs-docroot as docsroot %}**
31 {% if docsroot %}
32 <a href="{{ docsroot }}">{% trans 'Documentation' %}</a> /
33 {% endif %}
34 {% url admin:password_change as password_change_url %}
35 {% if password_change_url %}
36 <a href="{{ password_change_url }}">
37 {% else %}
38 <a href="{{ root_path }}password_change/">
39 {% endif %}
40 {% trans 'Change password' %}</a> /
在我看来,错误应该在这里:
(r'^ admin /',include(admin.site.urls)),
但我找不到。
感谢您的关注!!
答案 0 :(得分:2)
只是django似乎没有在你的模块vote
中找到函数views
。