How to add value to this "form.content" before rendering
class myform(forms.Form):
title = forms.CharField(max_length = 30)
content = forms.CharField(widget=MarkItUpWidget())
tag = forms.CharField(max_length = 30)
How to add value to this "form.content" before rendering
class myform(forms.Form):
title = forms.CharField(max_length = 30)
content = forms.CharField(widget=MarkItUpWidget())
tag = forms.CharField(max_length = 30)
Going on the extremely limited information you've given, you would use the initial
attribute of the content field:
content = forms.CharField(widget=MarkItUpWidget(), initial="This text will be in the field when it is rendered")
If you need the field to have dynamic values, you can do something like:
# forms.py
class MyForm(forms.Form):
def __init__(self, something_dynamic, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['content'].initial = "Some dynamic value"
# views.py
def my_view(request, ...):
something_dynamic = "some changing text"
form = MyForm(something_dynamic, ...)