How to create field named Â«fromÂ» in WTForms?
<p>I want to make a form for selecting an interval with two fields: <code>from</code> and <code>to</code>. But since <code>from</code> is a keyword in Python, I can't just write:</p>

<pre class="lang-python prettyprint-override"><code>class MyForm(Form):
    from = DateField()
    to = DateField()
</code></pre>

<p>This means that I have to name the field in Python differently but I still want to name the field in GET query exactly <code>from</code>. Is it possible with WTForms?</p>

<p>You can use Python's built in function <code>setattr</code>:</p>

<pre><code>class MyForm(Form):
    to = DateField()

setattr(MyForm, 'from', DateField())
myform = MyForm()
</code></pre>

<p>You can access the field again with <code>getattr</code>:</p>

<pre><code>from_ = getattr(myform, 'from')
</code></pre>

python wtforms