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 trialJude Molloy
7,470 PointsDjango Forms: Display a blank model form
I am not sure what to do here?
from django.shortcuts import render
from . import models
from . import forms
def product_form(request):
inst = get_object_or_404(models.Product)
form = forms.DigitalProductForm(instance=inst)
return render(request, 'products/product_form.html', {'form': form})
<form action='' method='POST'>
<input type="submit" value="Save">
</form>
1 Answer
Tatiana Vasilevskaya
Python Web Development Techdegree Graduate 28,600 PointsYou are trying to instantiate a model form for a Product instance, but you need a blank one.
form = forms.DigitalProductForm()
Just some heads up, if you want to instantiate a form with a Product instance, you need to import get_object_or_404 and you also have to pass a pk of a Product to get_object_or_404.
Jude Molloy
7,470 PointsJude Molloy
7,470 PointsThank you :)