开发者

django forms - reusing form request functions

开发者 https://www.devze.com 2023-04-04 09:44 出处:网络
I have a base.html which most of my pages inherit.Inside it defines a header which contains a search box.The code for the search box is some thing along the lines of....

I have a base.html which most of my pages inherit. Inside it defines a header which contains a search box. The code for the search box is some thing along the lines of....

if request.method == 'POST':
    if 'search_button' in request.POS开发者_开发问答T:
        location = request.POST['location']

         # Do something with location here and redirect to another page...

        return HttpResponseRedirect('/lostandfound')

I have a couple of questions. First of all, how do I ensure that this code is sat in all my other views without rewriting it every time, this wouldn't be very DRY!!

Also how do I redirect to another page and pass the variable 'location' along with it? HttpResponseRedirect isn't the right way to do it i'm sure!


You should POST your search form to it's own search view, and display the results on that page.

0

精彩评论

暂无评论...
验证码 换一张
取 消