So I am using Django version 1.6.5 and I am trying to create a simple form . and I have this view
def create(request):
if request.method == 'POST': # If the form has been submitted...
form = WatchForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
return HttpResponseRedirect('Watch/index.html') # Redirect after POST
else:
return render(request, 'Watch/create.html', {'form': form,})
else:
form = WatchForm() # An unbound form
return render(request, 'Watch/create.html', {
'form': form,
})
and this is my form
from django import forms
from 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 also created a template called create.html
<form action="" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
and this is my urlpatterns entry url(r'^create$',views.create),
So when I use this URL /watch/create/ the form does appear in my browser but when I submit I receive this error :
Page not found (404)
Request Method: POST
Request URL: http://127.0.0.1:8000/watch/create/
Using the URLconf defined in miWatch.urls, Django tried these URL patterns, in this 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']
The current URL, watch/create/, didn't match any of these.
and this is the output of the 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 is this happening and what is it that I am missing ?? Thanks in advance !