5👍
✅
i put the initial value direct in my views.py
…
def myviews(request):
.....
form = MyForm({'like':'Yes'})
...
8👍
Yes, this should be done in the view, but the syntax in the accepted answer is incorrect, as it will trigger field validation on all fields before submitting the form. Use instead:
def myviews(request):
.....
form = MyForm(initial={'like':'Yes'})
...
- Test if ValidationError was raised
- Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
- Django template keyword `choice_value` in no longer work in 1.11
- Gunicorn.socket: Failed with result 'service-start-limit-hit'
- Display a boolean model field in a django form as a radio button rather than the default Checkbox
- Form fields for ModelForm with inherited models
1👍
this is the way it works initial='N'
which is the first item in the tuple.
Choices=(('Y','Yes'), ('N','No')
rs_field = forms.ChoiceField(choices=Choices),initial='N', widget=forms.RadioSelect)
- How to use select_related with GenericForeignKey in django?
- Django – check if list contains something in a template
- TypeError at /en/ Object of type '__proxy__' is not JSON serializable
- Django: How to check if something is an email without a form
- Invalid HTTP_HOST header: The domain name provided is not valid — requests to dockerized django app using container name
Source:stackexchange.com