Test Flask render_template() context

前端 未结 4 988
滥情空心
滥情空心 2020-12-24 12:02

I have a Flask route that looks like this:

@app.route(\'/\')                                                                 
def home():                             


        
4条回答
  •  青春惊慌失措
    2020-12-24 12:41

    You may want to use Jinja setup in your Html page, pass the variable to the page and see if updated.

    http://flask.pocoo.org/docs/0.11/templating/#jinja-setup

    http://jinja.pocoo.org/

    As an example:

    flask template

    @app.route('/')                                                                 
    def home():                                                                                                                  
        return render_template(                                                     
            'home.html',                                                            
            greetingDictionary = {"greeting": "hello" , "forthoseabouttorock" :"wesaluteyou" }                                       
        )   
    

    html page

    {% for key in greetingDictionary %}
    

    {{key}}

    {{greetingDictionary[key]}}

    {% endfor %}

提交回复
热议问题