Home > front end >  Textarea not displaying placeholder in Python and Flask
Textarea not displaying placeholder in Python and Flask

Time:12-06

I have a Python variable being returned in a textarea, however, when the variable returns nothing none is displayed instead of reverting back to the placeholder text.

Examples:

<textarea placeholder="some text">{{ variable }}</textarea>

Attempt:

<textarea placeholder="some text">
 {% if result %}
   {{ variable }}
 {% endif %}
</textarea>

CodePudding user response:

If you want the placeholder text to be displayed when the result variable is empty or not defined, you can use the else statement in your Jinja2 code. Here is an example of how you can modify your code to achieve this:

<textarea placeholder="some text">
 {% if result %}
   {{ result }}
 {% else %}
   {{ placeholder }}
 {% endif %}
</textarea>

In this example, if the result variable is defined and not empty, it will be displayed in the textarea. If the result variable is not defined or is empty, the placeholder text will be displayed instead.

  • Related