How can I combine Vue.js with Flask?

后端 未结 2 856
庸人自扰
庸人自扰 2020-12-22 20:23

I want to use Vue.js and Flask together: Vue.js for a dynamic front-end, and Flask for the back-end. How can I do that?

2条回答
  •  北海茫月
    2020-12-22 20:42

    When using vue-cli or Webpack, process can be simplified. Simply create

    vue.config.js in your Vue project, see: Vue config

    module.exports = {
        outputDir: "../dist",
    
        // relative to outputDir
        assetsDir: "static" 
    };
    

    then config your flask app:

    app.py

    from flask import Flask, render_template
    
    app = Flask(__name__,
                static_folder = "./dist/static",
                template_folder = "./dist")
    
    
    @app.route('/')
    def index():
        return render_template("index.html")
    

    Note, that in flask static_folder and template_folder can't be the same.

提交回复
热议问题