Laura
Laura

Reputation: 9

How to display the Form properly?

I just want to show a Form on a HTML Page. When I put it on the Page and look via Web Browser, there seems to show me the memory address instead of rendering the form..

[forms.py]

from django import forms

MODES=[('top10', 'Top 10 Songs'),
    ('last10', 'Last 10 Songs'),
    ('recentX', 'Recent X Songs')]

class chooseMode():
    first_name = forms.CharField(required=True)
    selectMode = forms.ChoiceField(label='Choose Mode', widget=forms.RadioSelect,choices=MODES)

[views.py]


def home(request):
    modusFormular = chooseMode()

    return render(request, 'home.html', {'modusForm' : modusFormular})

[home.html] somewhere in body: {{ modusForm }}

I expected the form to be shown on the page, but it shows me the following:

<mysongproject.forms.chooseMode object at 0x7fcdcae97710>

Upvotes: 1

Views: 43

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599906

Your class needs to inherit from Form:

class chooseMode(forms.Form):

Upvotes: 1

Related Questions