There is a Django form. When I send a GET-request, I output a new empty form, when I click "Submit", I display on the page what the user entered in the questionnaire. The problem is that I want some data to be output not as an internal representation, but as an full one (idk how it called correctly). I'm a beginner in Django and may not understand many nuances.
I tried to add data to the dictionary individually, but it didn't lead to anything.
pool.html:
<p><b>Ваше имя:</b> {{ form_data.name }}</p>
<p><b>Ваш пол:</b> {{ form_data.get_sex_display }}</p>
forms.py:
class FeedbackForm(forms.Form):
SEX_OPTIONS = (
('m', 'Мужской'),
('f', 'Женский'),
('none', 'Паркетный')
...
sex = forms.ChoiceField(
widget=forms.RadioSelect,
choices=SEX_OPTIONS,
label='Ваш пол:'
)
views.py:
def pool(request):
assert isinstance(request, HttpRequest)
context['title'] = 'Обратная связь'
if request.method == 'GET':
form = FeedbackForm()
else:
form = FeedbackForm(request.POST)
if form.is_valid():
form_data = request.POST.dict()
context['form_data'] = form_data
context['form'] = form
return render(request, 'app/pool.html', context=context)