0

I am a beginner in Django. When I run my program I got the following error.

Exception Type:     ViewDoesNotExist
Exception Value:    

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

I have a search Function in my view:

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>

Can you please help me?

Here is my url file. I updated it. But, now it tells me syntax error at url.py file:

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)),
)
4

2 回答 2

1

在您的 urls.py 中,您指的是polls.views.output但不在您的 views.py 中。polls.views.search如果您为该视图添加了 url,您可能需要更正它。

于 2012-11-09T06:06:41.093 回答
0

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

于 2012-11-09T05:48:52.053 回答