视图不存在

时间:2012-11-09 04:53:11

标签: django django-forms django-views

我是Django的初学者。当我运行我的程序时,我收到以下错误。

Exception Type:     ViewDoesNotExist
Exception Value:    

Could not import polls.views.output. View does not exist in module polls.views.

我的视图中有一个搜索功能:

def search(request):
    c = {}
    c.update(csrf(request))
    if request.method == 'POST': # If the form has been submitted...
        form = Search(request.POST) # A form bound to the POST data  
        if form.is_valid():
            search_query=form.cleaned_data['query']
            pi=add.add(search_query)
            return render_to_response('polls/output.html',{'pi': pi}) # Redirect after POST
    else:
        form=Search()
        return render_to_response(request, 'polls/search.html', c.update(form=form))

output.html
    <ul>
    {% for p in pi %}
       <li>{{p}}</li>
    {% endfor %}
    </ul>

你能帮帮我吗?

这是我的网址文件。我更新了它。但是,现在它告诉我url.py文件中的语法错误:

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^mysite/', include('mysite.foo.urls')),
    url(r'^polls/output$', 'polls.views.search')
    url(r'^polls/search$', 'polls.views.search'),
    url(r'^polls/$', 'polls.views.index'),
    url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
    url(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
    url(r'^polls/(?P<poll_id>\d+)/vote/$', 'polls.views.vote'),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)

2 个答案:

答案 0 :(得分:1)

在你的urls.py中,你指的是polls.views.output,但你的views.py中没有。{如果您为该视图添加了网址,则可能需要将其更正为polls.views.search

答案 1 :(得分:0)

该错误与您的视图代码无关。检查您的导入