Writing a very basic search form in Django

后端 未结 1 966
梦谈多话
梦谈多话 2020-12-28 10:10

So I\'m trying to get something very simple accomplished. I want to enter a term into my search box, and display it on the resulting page.

My HTML for the form is

相关标签:
1条回答
  • 2020-12-28 10:50

    Ok so the action handling the search in your views.py is supposed to be search but as I suspected in your urls.py you don't call the search method anywhere.

    Where do you execute search method?

    Urls should be like this:

    urlpatterns = patterns('',
    url(r'^home/$', 'search.views.home'),
    url(r'^results/$', 'search.views.search'),
    # or at least have a url for the search view
    

    Note the action attribute in your form

    It is action="/results/". This means result view is the one who is supposed to be handling the form. You may also change this to action="/search/" and have your urls like this:

    urlpatterns = patterns('',
    url(r'^home/$', 'search.views.home'),
    url(r'^results/$', 'search.views.results'),
    url(r'^search/$', 'search.views.search'),
    
    0 讨论(0)
提交回复
热议问题