Python (Flask) serving Angular project's index.html file

前端 未结 3 543
后悔当初
后悔当初 2021-01-05 15:30

Does anyone know how to serve an Angular single page application using Flask?

I\'m having trouble serving the default route, \'/\', which should load index.html and

3条回答
  •  被撕碎了的回忆
    2021-01-05 16:11

    As mentioned in Flask docs:

    Just create a folder called static in your package or next to your module and it will be available at /static on the application.

    So, if you use the template in:

    templates/dist/templates/index.html
    static/ # set static folder there
    

    Or, depending how you have your application sorted:

    templates/dist/static/ # set static folder there
    

    Have a look at how they sort the application in the docs:

    /application.py
    /templates
        /hello.html
    

    or if you use module folders:

    /application
        /__init__.py
        /templates
            /hello.html
    

提交回复
热议问题