python - Django Forms error when calling requesting POST method -
python - Django Forms error when calling requesting POST method -
so using django version 1.6.5 , trying create simple form . , have view
def create(request): if request.method == 'post': # if form has been submitted... form = watchform(request.post) # form bound post info if form.is_valid(): # validation rules pass homecoming httpresponseredirect('watch/index.html') # redirect after post else: homecoming render(request, 'watch/create.html', {'form': form,}) else: form = watchform() # unbound form homecoming render(request, 'watch/create.html', { 'form': form, })
and form
django import forms watch.models import watch class watchform(forms.form): idnumber=forms.charfield(max_length=30) brand = forms.charfield(max_length=200) #reliseddate =forms.datetimefield('date published') referencenumber = forms.charfield(max_length=30) sortdescription=forms.charfield(max_length=200) fulldescription=forms.charfield(max_length=600)
i have created template called create.html
<form action="" method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="submit" /> </form>
and urlpatterns entry url(r'^create$',views.create),
so when utilize url /watch/create/ form appear in browser when submit receive error :
page not found (404) request method: post request url: http://127.0.0.1:8000/watch/create/ using urlconf defined in miwatch.urls, django tried these url patterns, in order: ^watch/ ^$ [name='index'] ^watch/ ^create$ ^watch/ ^(?p<watch_id>[0-9]+)/$ [name='detail'] ^watch/ ^(?p<watch_id>[0-9]+)/results/$ [name='results'] ^watch/ ^(?p<watch_id>[0-9]+)/vote/$ [name='vote'] current url, watch/create/, didn't match of these.
and output of monitor
[23/jun/2014 07:53:52] "get /watch/create http/1.1" 200 1084 [23/jun/2014 07:54:01] "post /watch/create/ http/1.1" 404 2766 [23/jun/2014 07:54:08] "get /watch/create/ http/1.1" 404 2765
anybody can give me clarification on why happening , missing ?? in advance !
change action
attribute in form as
<form action="" method="post">
this submit form current url.
python django django-forms
Comments
Post a Comment