Answer the question
In order to leave comments, you need to log in
How to pass user data to variable in Django widget?
Good day, I hope you can help me. There is a small script for displaying the widget, but I can’t understand how to accept the value selected by the user and pass it to a variable with subsequent use, please tell
me Views.py
def countries_view(request):
if request.method == 'POST':
form = CountryForm(request.POST)
if form.is_valid():
countries = form.cleaned_data.get('countries')
# как принять значение ?
else:
form = CountryForm
return render('index.html', {'form': form})
class CountryForm(forms.Form):
OPTIONS = (
("AUT", "Austria"),
("DEU", "Germany"),
("NLD", "Neitherlands"),
)
Countries = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=OPTIONS)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question