Python flask jinja image file not found

前端 未结 2 674
清酒与你
清酒与你 2021-01-01 20:45

Newbie question.

I am using Flask, a webframe for Python. Flask uses Jinja to render the template. I do not know which version of Jinja Flask uses, nor do I know how

相关标签:
2条回答
  • 2021-01-01 21:11

    For Flask, you should keep the static files usually under a folder "static" and then use the url_for function. Lets say your project is called "myproject" and using your example, it should look something like:

    myproject/
        app.py
        templates/
        static/
            css/
                images/
                    icons/
                        resultset_previous.png
    

    Then in the template, you can call

    <img src= {{ url_for('static', filename = 'css/images/icons/resultset_previous.png') }} width="16" height="16" alt="previous" title="Previous" border="0">
    

    Also, to answer your question about jinja versions etc, check this out

    https://github.com/mitsuhiko/flask/blob/master/.travis-lowest-requirements.txt

    0 讨论(0)
  • 2021-01-01 21:11

    See this section of the Flask documentation.

    The correct way to refer to the static file from your template is:

    <img src="{{ url_for('static', filename = 'css/images/icons/resultset_previous.png') }}" width="16" height="16" alt="previous" title="Previous" border="0">
    
    0 讨论(0)
提交回复
热议问题