On Thu, Aug 20, 2015, at 17:43, Edgar Gabaldi wrote:
> The code seems right. Probably your form has some error. Try print
> {{form.errors}} in your template to check.
Shouldn't {{ form.as_p }} include errors as well? This seems to be what
the doc indicates:
https://docs.djangoproject.com/en/1.8/topics/forms/#working-with-form-templates
> On Thu, Aug 20, 2015 at 4:45 PM, Hugo Kitano
> <[email protected]> wrote:
>> Hi, I'm a beginner using Django, and I'm having trouble using model
>> forms to create instances of my model. When a user submits a form,
>> the database saves nothing. Here's my code for the view
>>
>> def submit(request):
>> SubmissionForm = modelform_factory(Submission, fields=('sub_name',
>> 'sub_file'))
>> if request.method == "POST":
>> form = SubmissionForm(request.POST)
>> if form.is_valid():
>> model_instance = form.save(commit=False)
>> model_instance.sub_date = timezone.now()
>> model_instance.save()
>> return HttpResponseRedirect('http://localhost:8000/stats/')
>> else:
>> form = SubmissionForm()
>> return render(request, 'stats/submit.html', {'form': form})
>>
>> And here's my template:
>>
>> <h1> Submit form: </h1> <form action="/stats/" method="post"> {%
>> csrf_token %} {{ form.as_p }} <input type="submit"
>> value="Submit" /> </form>
>>
>> I'd appreciate any help. Thansk!
>>
>>
>> Hugo
>>
>>
>>
>>
--
>>
You received this message because you are subscribed to the Google Groups
"Django users" group.
>>
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
>>
To post to this group, send email to [email protected].
>>
Visit this group at http://groups.google.com/group/django-users.
>>
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/af4016f0-65e5-4a5c-99e9-7f544e7ced7c%40googlegroups.com[1].
>>
For more options, visit https://groups.google.com/d/optout.
>
>
> --
>
You received this message because you are subscribed to the Google Groups
"Django users" group.
>
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
>
To post to this group, send email to [email protected].
>
Visit this group at http://groups.google.com/group/django-users.
>
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAGjPPHn0f-rdRKDd4J9sA%3DVbH4R7zTvyPmMYv-dCb80%3DiLq%2Bsg%40mail.gmail.com[2].
>
For more options, visit https://groups.google.com/d/optout.
--
Hugo Osvaldo Barrera
Links:
1.
https://groups.google.com/d/msgid/django-users/af4016f0-65e5-4a5c-99e9-7f544e7ced7c%40googlegroups.com?utm_medium=email&utm_source=footer
2.
https://groups.google.com/d/msgid/django-users/CAGjPPHn0f-rdRKDd4J9sA%3DVbH4R7zTvyPmMYv-dCb80%3DiLq%2Bsg%40mail.gmail.com?utm_medium=email&utm_source=footer
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/1440149087.1060796.362092089.25AF4C3C%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.