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 trial

Python Django Forms Model Forms Display a Blank Model Form

Django Forms: Display a blank model form

I am not sure what to do here?

products/views.py
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})
products/templates/products/product_form.html
<form action='' method='POST'>
    <input type="submit" value="Save">
</form>

1 Answer

Tatiana Vasilevskaya
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tatiana Vasilevskaya
Python Web Development Techdegree Graduate 28,600 Points

You 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.

Thank you :)