0
class CountryLevelOptimization(forms.Form):
    name = forms.CharField()
    country = forms.ChoiceField(widget=forms.Select, choices=(('A','a'),('B','b')))

Above is my Django form in which country is a ChoiceField Following is my python code.

def Homepage(request):
    choices = (('Country1','India'),('Country2','USA'))
    form = CountryLevelOptimization()
    # How to pass choices to the form['country'] 
    return render(request,"Dummy.html",{"form":form})

How can i pass choices to the country in from the view Homepage ?

please help me with this.

SBN AB
  • 161
  • 1
  • 1
  • 17
  • Possible duplicate of [Creating a dynamic choice field](https://stackoverflow.com/questions/3419997/creating-a-dynamic-choice-field) – Sam Dec 24 '17 at 17:06
  • @Sam i actually have followed the steps of **Creating a dynamic choice field** link showed by you. But, how do i get the request back. **wayout(request.POST)** does not work as we are passing only 1 argument. But our class is taking two arguments – SBN AB Dec 26 '17 at 06:33
  • Could you update your question with the latest code so that I can take a look at it? Thanks in advance! – Sam Dec 27 '17 at 21:07

0 Answers0