目录:

  一、变量引用

 

内容:

   备注:PyCharm小技巧,comm+alt+l  自动修改格式,comm+alt+return  向上添加新行

  一、变量引用

  1、url生成

  

from flask import Flask,render_template #在Flask中使用render_template代替render使用

app = Flask('__name__')


@app.route('/') #所有的url都使用app.route做装饰器来引用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="{{ url_for('static',filename='style.css') }}"/>
</head>
<body>
<h1>{{ title }}</h1>
<a href="{{ url_for('.services') }}">Services</a>
<a href="{{ url_for('.about') }}">About</a>
</body>
</html>

 

def hello_world():
    return render_template('index.html', title='Hello World')

@app.route('/services')
def services():
    return 'Services!'

if __name__ == '__main__':
    app.run()

   2、增加debug

from flask import Flask

app = Flask(__name__)


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


if __name__ == '__main__':
    app.run(debug=True) #增加这个参数,可以在修改完毕后不重启直接运行
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2021-10-29
  • 2021-09-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2022-01-03
  • 2021-07-23
  • 2021-10-11
相关资源
相似解决方案