开发者

post form in django, get blank screen, broken or bug?

开发者 https://www.devze.com 2023-04-04 20:33 出处:网络
I\'ve created a form in django which works fine on desktop browsers, but on mobile browsers when the form submits it just displays a blank screen (doesn\'t even load the title or an error), am I missi

I've created a form in django which works fine on desktop browsers, but on mobile browsers when the form submits it just displays a blank screen (doesn't even load the title or an error), am I missing something?

If there's no way to make it work using post, how could I submit a form to locations/<zip code> or use get locations/?zip_code=<zip code>? (I'm a django noob, sorry)

here's the relevant code:

template:

<form action="" method="post">
    {{ form.as_p }}
    <input type="submit" value="Submit" />
</form>

form.py:

class ZipForm(forms.Form):
    zip_code = forms.CharField(max_length=10)

views.py:

def zip(request):
    if request.method == "POST":
        form = ZipForm(request.POST)
     开发者_如何转开发   if form.is_valid():
            zip_code = form.cleaned_data['zip_code']
            ## get result    
            return render_to_response("zip.html",{
                'title':'Closest Locations',
                'results' : results,
                'form' : form,
            })
    else:
        form = ZipForm()
    return render_to_response("zip.html", {
        'form' : form,
        'title' : 'Find Locations',
    })

url.py:

url(r'^locations/$', 'app.views.zip'),

I wish there was a decent debugger for developing on mobile phones, ugh.


If the form is valid then you do all this fancy stuff... but you forgot to handle the case where the form isn't valid.

0

精彩评论

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

关注公众号