开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜