Flask+Vue 使用

发布时间 2023-03-24 15:29:13作者: Ratooner

Vue 项目经过npm run build 打包后生成文件在dist目录如下:

 

 

 app.py:

from flask import Flask, render_template

# 设置静态文件夹目录 static_folder='./dist'
# 设置vue编译输出目录dist文件夹,为Flask模板文件目录,template_folder='./dist'
app = Flask(__name__, static_folder='./dist', template_folder='./dist')

@app.route('/')
def index():
return render_template('index1.html')

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

index1.html:

<!doctype html>
<html lang="">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="icon" href="./dist/favicon.ico">
    <title>test1</title>
      <script defer="defer" src="./dist/js/chunk-vendors.9d61cd2a.js"></script>
    <script defer="defer" src="./dist/js/app.1ba132cd.js"></script>
    <link href="./dist/css/app.2cf79ad6.css" rel="stylesheet ">
  </head>
  <body>
    <noscript><strong>We're sorry but test1 doesn't work properly without JavaScript enabled. Please enable it to
        continue.</strong></noscript>
    <div id="app"></div>
  </body>
</html>