Flask基本知识


@app.route('/')
def hello_world():
return 'Hello World!'

#route动态Route,支持字符串、整数、浮点数,/user/<int:id>
@app.route('/user/<name>')
def user(name):
return '<h1>Hello,{}!</h1>'.format(name)
  #使用模板渲染,user.html模板在templates目录下
  return render_template('user.html',name=name)

模板中的控制语句 

{% if user%}

  Hello,{{ user }}

{ % else %}

  Hello,stranger

 {{ % endif%}}

 

<ul>

  {% for comment in comments %}

    <li>{{ comment }}</li>

  {% endfor %}

</ul>




if __name__ == '__main__':
app.run()
posted @   村西崔二  阅读(154)  评论(0编辑  收藏  举报
编辑推荐:
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
阅读排行:
· PPT革命!DeepSeek+Kimi=N小时工作5分钟完成?
· What?废柴, 还在本地部署DeepSeek吗?Are you kidding?
· DeepSeek企业级部署实战指南:从服务器选型到Dify私有化落地
· 程序员转型AI:行业分析
· 重磅发布!DeepSeek 微调秘籍揭秘,一键解锁升级版全家桶,AI 玩家必备神器!
点击右上角即可分享
微信分享提示