All fields of your model are required. Thus, form.is_valid()
will be True if all fields are filled with the correct values ββand will not be filled. You declared the fields time
, user
, views
as hidden fields. Are you sure you filled them in your form? In addition, you can specify the automatic stamping field time = models.DateField()
. Change the model field, for example
time = models.DateField(auto_now=True)`.
After that, you do not need to fill it yourself in the form of a template.
Your view should return an HttpResponse object in all cases . If your form is invalid, i.e. If form.is_valid()
returns False, then the HttpResponse
object will not be returned by your view. This may be the source of your failure. Add an else
for if form.is_valid()
:
from django.http import Http404 def new(request): if request.method == 'POST':
stalk source share