0

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)
user1288625
  • 15
  • 1
  • 5
  • possible duplicate of [How to add default value to django-markitup widget?](http://stackoverflow.com/questions/9849975/how-to-add-default-value-to-django-markitup-widget) – Alasdair Mar 24 '12 at 18:32

1 Answers1

1

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, ...)
Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
  • But How to add value dynamically in a function view ?? – user1288625 Mar 24 '12 at 18:54
  • Again, not sure what you are asking, but if you need to create the dynamic value from within your view, and you are wondering how to have that value availble within the form, look at my edited answer – Timmy O'Mahony Mar 24 '12 at 19:02