Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Jose Cuervo
Aug 25, 2004
Hope it is ok to post this question here, happy to be pointed to a more relevant thread if need be.

I am building a small website using Flask and in one HTML page I need to include javascript files depending on the report type selected by the user. This is my code using Jinja2 (using images because SA was blocking me posting the code):
https://imageupload.io/kKoVPz0GQPPzZ7D

The resulting HTML code is
https://imageupload.io/zh4Y2WMLelxIqkl

I believe the code does not work because I am nesting the "{{ }}" (once around the url_for function and once around the jsFilename). Is this the issue? If this is the issue, how do I deal with it?

Adbot
ADBOT LOVES YOU

Jose Cuervo
Aug 25, 2004

minato posted:

Try:
code:
... src={{ url_for('static', filenamt='js/reports/' ~ jsFilename ~ '.js') }}
and maybe this will work too:
code:
... src={{ url_for('static', filenamt='js/reports/' ~ (jsFilename | safe) ~ '.js') }}

Both versions worked! Do you mind pointing me to some documentation or tell me what keyword to use to find the ~ as what to use? EDIT: I found it here: https://jinja.palletsprojects.com/en/3.1.x/templates/ under the "Other Operators". I definitely missed that when I was looking through the documentation.

I also ended up finding this solution which would have worked for my use case: https://stackoverflow.com/a/19511353/3130499

Jose Cuervo fucked around with this message at 16:40 on Oct 19, 2023

Jose Cuervo
Aug 25, 2004
Mistaken post.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply