Sunday, 15 May 2011

Python flask jinja image file not found -


Newbie Question

I am using a webframe for flasks, Python. Uses Genja to render the flask template. I do not know which version of Jinnah Flask uses, and I do not know how to recover Jinnah version or flask version. I use Python version 2.7.

The template has an image in the CSS / image directory. This image is showing while viewing the template as a file directly in the Firefox browser.

but not while executing the flask:

  flask import flask, render_template app = flask (__name__) @ app. Root ('/ Hello /') @ app Root ('/ Hello / Lt; Name & gt;') Hello Deaf (name = none): Return reader_template ('Basic' 'name, name = name) __name__ ==' __main__ ': app.debug = true app .run ()   

The contents of the HTML file:

  & lt ;! DOCTYPE HTML & gt; & Lt; Html & gt; & Lt; Body & gt; & Lt ;! - variable example start - & gt; {% If name%} & lt; H1 & gt; Hi {{name}}! & Lt; / H1> {% Else%} & lt; H1 & gt; Hello World! & Lt; / H1> {% Endif%} & lt ;! - variable example end - & gt; & Lt; Img src = "css / images / icons / resultset_previous.png" width = "16" height = "16" alt = "previous" title = "previous" range = "0" & ​​gt; & Lt; / Body & gt; & Lt; / Html & gt;   

Template runs fine and variable example runs as expected but images are not displayed Debug returns: "GET /hello/css/images/icons/resultset_previous.png HTTP / 1.1" 404 -

I run the flask in virtual env as explained in the documentation. The path of the image seems unknown, for the flask, you should place the stationary folder normally under a folder called "static" and then use the url_for function to say that your project is called "my project" and your example It should look something like this:

  myproject / app.py template / static / css / images / icon / result pivres   

Then in the template, you can call

  & lt; Img src = {{url_for ('static', filename = 'css / images / icons / resultset_previous .png')}} width = "16" height = "16" alt = "previous" title = "previous" limit = " 0 "& gt;   

In addition, to answer your question about jinja version etc., check it



No comments:

Post a Comment