I have a Django server running localy at http://localhost:8000
, with a view set over url /register/
.
There I have an html file with a form. The view is correctly displayed. But when I push a button, a POST request should be generated, but Django doesn't receive any request.
I don't know if I am setting a wrong host to make the post or I'm having a different trouble, because when testing at jsFiddle from Firefox for windows, I can see the POST with Firebug; but if I use Firefox&Firebug for Ubuntu, at the virtual machine where I'm running Django, no POST request is catched by Firebug.
#views.py
def formExample1(request):
print 'RECEIVED REQUEST: ' + request.method
if request.method == 'POST':
startHour = request.REQUEST['starthour']
endHour = request.REQUEST['endhour']
return HttpResponseRedirect('http://www.google.es')
else: #GET
return render(request, 'formExample1.html')
urls.py
urlpatterns = patterns('',
url(r'^register/$', 'helloworld.views.formExample1'),
)
And formExample1.html looks like this:
<script>
...
// Play button
$( "#id_playButton" ).click(function() {
var postdata = {
'starthour': $("#id_interval").slider("values", 0),
'endhour': $("#id_interval").slider("values", 1)
}
$.post('register/', postdata)
});
</script>