Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a value to WTForms field with Jinja2

This is probably super simple. But I'm using WTForms and want to set the value of a field to a variable I pull from the database. But instead of displaying the dynamic variable, it's displaying the variable name.

{{ form.question.label }}
{{ form.question(value="{{ q.question }}") }}

{{ form.slug.label }}
{{ form.slug(value="{{ q.slug }}") }}

So in the field it says "{{ q.question }}" instead of something like "What is the meaning of life?".

Is there a way to display nested variables in Jinja? Or is there some other way I need to go about this? Any help is appreciated!

like image 930
TylerW Avatar asked Oct 28 '13 21:10

TylerW


1 Answers

take out the double quotes and the template tags.

{{ form.question(value=q.question) }}

and the same for slug

like image 65
Back2Basics Avatar answered Nov 13 '22 07:11

Back2Basics