Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask Compare strings

Tags:

python

flask

If I upload a file to my flask script and I don't like it, I set filename to "None" so it shows a default image. Then, in my Flask template, I want to test to see if filename is "None"; if so, show the default. Else, show the file. Here is my template code, which does not work:

<!doctype html>
<title>Hello from Flask</title>
{% if {{filename}} is "None" %}:
  <h1>some text<img src="{{filename}}"> more text!</h1>
{% else %}
  <h1>Impossible file: here is tha default so<img src="MB.png"> boi</h1>
{% endif %}

I think the problem lies in the string compare. I cannot figure out how to properly compare strings, I think.

Thanks!

like image 730
Uzebeckatrente Avatar asked Jan 16 '26 22:01

Uzebeckatrente


1 Answers

What about this?

{% if filename == "None" %}

You don't need double brackets inside {% %}

Ex: https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#operator

like image 69
JulienD Avatar answered Jan 19 '26 19:01

JulienD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!