[Answer]-Do you need the Django template brackets to pass string values in a form?

1👍

Actually, the second way is kind of overkill:

<input type="radio" name="question_1" value="{{ 'Option2'  }}">Option 2<br>

You’re telling the template engine to parse 'Option2' python statement. Since 'Option2' python statement yields a string, the template engine will substitute it with:

<input type="radio" name="question_1" value="Option2">Option 2<br>

Which is exactly the same as your first way. You’re creating a little overhead by doing it the second way.

Brackets are used inside templates to perform some kind of computation inside the template domain. Like accessing a view‘s variable or object method.

To answer your question, you don’t need the brackets syntax to include literals in the template. You need them to output variable values in it.

Hope this helps!

Leave a comment