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 trialDevin Reeh
Courses Plus Student 6,314 PointsDjango Forms Challenge Task
We've made models and model forms, now we need a view to render the form. Write a new view named product_form that instantiates the DigitalProductForm and provides it to the products/product_form.html template as the key "form".
I know that I'm supposed to instantiate the model in the view, but I don't think I'm doing it right. Please help with an explanation to your code pretty please! Or maybe a link to a vid where they explain what I'm doing wrong if you know. Thank you so much! Much appreciated.
from django.shortcuts import render
from . import forms
def product_form(request):
form = forms.DigitalProductsForm()
if request.method = 'POST':
form = forms.digitalProductsForm(request.POST)
if form.isValid():
<form action='' method='POST'>
<input type="submit" value="Save">
</form>
4 Answers
Allison Schaaf
33,322 PointsDon't overthink it too much.
from django.shortcuts import render
from . import forms
def product_form(request):
form = forms.DigitalProductForm()
return render(request, 'products/product_form.html', {'form': form})
Calum Devitt
3,763 Pointsim stuck on this one too
Michael Delgado
18,792 PointsI had trouble as well. The question is not asking you to check if it is "POST" or if it is valid. You have instantiated the form, now render it.
Ker Zhang
Full Stack JavaScript Techdegree Graduate 29,113 Pointsdef product_form(request): form = forms.DigitalProductForm() return render(request, 'products/product_form.html', {'form':form})
this worked for me.