[Answer]-How to call form in template when using generic.FormView in django?


I found the answer. Its how you include choices in django forms. So CATEGORY_CHOICES has to be a list of tuples, which it was not in this case.

Thus, this simple change made it work:

CATEGORY_CHOICES = [('', cat.title)
                    for cat in Category.objects.all()]


The FormView supplies a context variable called form that holds your actual form object, so you can use:

{{ form.as_table }}

Or any of the other rendering options that form supplies. See: https://docs.djangoproject.com/en/dev/topics/forms/#displaying-a-form-using-a-template


Leave a comment