模板参数

无纤尘

模板参数
1、在使render_template
渲染模板的时候,可以传递关键字参数,以后直接在模板中使用就可以了。

@app.route('/')
def hello():
    context = {
        'username': 'yueyue',
        'age' : 18
    }
    return render_template('index.html', username='yueyue', age=18)

2、如果参数过多,那么可以将所有的参数放到一个字典中,然后在传这个参数的低吼,使用双星号,将字典分解成关键字参数

@app.route('/')
def hello():
    context = {
        'username': 'yueyue',
        'age' : 18
    }
    return render_template('index.html',**context)

版权协议须知!

本篇文章来源于 岳岳 ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

1330 0 2020-12-01


分享:
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
  • 默认
  • 护眼
  • 夜晚
  • 壁纸
  • 默认