Eine Variante hab ich nun gefunden, hier mal ein Beispiel:
Code: Alles auswählen
from django import forms
from django.http import QueryDict
POST = QueryDict(query_string="foo=bar")
print POST
class Form(forms.Form):
foo = forms.CharField()
form = Form(POST)
form.is_valid()
print form.cleaned_data
print form.as_p().replace(">",">\n")
# Ansonsten: AttributeError: This QueryDict instance is immutable
form.data._mutable = True
form.data["foo"] = "new"
form.data._mutable = False
print form.as_p().replace(">",">\n")
Code: Alles auswählen
<QueryDict: {u'foo': [u'bar']}>
{'foo': u'bar'}
<p>
<label for="id_foo">
Foo:</label>
<input type="text" name="foo" value="bar" id="id_foo" />
</p>
<p>
<label for="id_foo">
Foo:</label>
<input type="text" name="foo" value="new" id="id_foo" />
</p>
Fällt irgendwem eine bessere Lösung ein?
btw. es ist für einen Markup Konverter in PyLucid ( http://code.google.com/p/python-creole/ ).