Do you have any idea what could be causing the problem, then?

On Friday, August 21, 2015 at 2:25:17 AM UTC-7, Hugo Osvaldo Barrera wrote:
>
>  
>  
>  
> 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 <hkit...@gmail.com 
> <javascript:>> 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 django-users...@googlegroups.com <javascript:>.
> To post to this group, send email to django...@googlegroups.com 
> <javascript:>.
> 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
>  
> <https://groups.google.com/d/msgid/django-users/af4016f0-65e5-4a5c-99e9-7f544e7ced7c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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 django-users...@googlegroups.com <javascript:>.
> To post to this group, send email to django...@googlegroups.com 
> <javascript:>.
> 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
>  
> <https://groups.google.com/d/msgid/django-users/CAGjPPHn0f-rdRKDd4J9sA%3DVbH4R7zTvyPmMYv-dCb80%3DiLq%2Bsg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>  
> --
> Hugo Osvaldo Barrera
>  
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/a1eaac7c-4fb5-4c1c-b06e-4efdfbbb4e2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to