Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHeidi Ulrich
4,624 PointsPlease find the error in my code
The only error I get is this, and that doesn't help me much. What do I do wrong?
Bummer! Hmm, didn't find the newly-created product.; Hmm, didn't get a redirect for the product_form view as a POST.
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render
from . import forms
def product_form(request):
form = forms.DigitalProductForm()
if request.method == 'POST':
if form.is_valid():
form.save()
HttpResponseRedirect(reverse('products:create'))
return render(request, 'products/product_form.html', {form: 'form'})
2 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsYou are close. The hints mentions Instantiate a new form with request.POST this means to use request.POST
as an argument to forms.DigitalProductForm()
The results of the HttpResponseRedirect statement should be return
ed.
Heidi Ulrich
4,624 PointsAh, with that, I could solve it! Instantiated the form with the argument, then returned the HttpResponseRedirect :) Thank you!