2

Is there a way to have something similar to Djangos {{ MEDIA_URL }} tag in a Flask application?

Originally I simply wanted to use the static_url_path option for this, but Werkzeug won't create url route for paths that doesn't start with '/'. This seems reasonable enough when I thought about it a bit more.

The second option, that does work, but which I dislike, is to simply parse a MEDIA_URL variable to every single render_template. I would like my solution to be a bit more automatic, if that's possible.

Is there a way to inject a variable into every single jinja2 template in advance or do I have to live with either parsing my MEDIA_URL to very template or hardcode the img, css and javascript paths into my templates?

Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
Simon
  • 520
  • 1
  • 4
  • 13
  • 2
    Found the answer 30 seconds after posting the question: http://stackoverflow.com/questions/7017990/get-variables-from-a-settings-py-file-in-a-jinja-template-with-flask – Simon Oct 31 '11 at 19:48
  • 2
    you should post the answer and accept it - it will help others with the same problem :-) – Sean Vieira Oct 31 '11 at 21:57

0 Answers0