栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Python(Flask)服务Angular项目的index.html文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python(Flask)服务Angular项目的index.html文件

为了简化设置,请考虑在构建过程中使用Angular
CLI
将所有文件放置在分发目录中,即通过

outputPath
在angular.json中指定。您可以
assets
在构建期间使用angular.json部分移动您的Python文件。

angular.json

"your-project": {  "root": "your-project-directory",  "sourceRoot": "your-project-directory/src",  "projectType": "application",  "architect": {    "build": {    "builder": "@angular-devkit/build-angular:browser",    "options": {      "outputPath": "dist",      "index": "your-project-directory/src/index.html",      "main": "your-project-directory/src/main.ts",      ...      "assets": [        {          "glob": "***",          "input": "your-project-directory/src/python/",          "output": "."        }

dist
目录的顶层,将您
main.py
的基本Flask设置与一起放置
index.html
。注意 static_proxy
以确保提供支持文件。

main.py

from flask import Flask, send_from_directoryapp = Flask(__name__)@app.route('/<path:path>', methods=['GET'])def static_proxy(path):  return send_from_directory('./', path)@app.route('/')def root():  return send_from_directory('./', 'index.html')if __name__ == '__main__':  # This is used when running locally only. When deploying use a webserver process   # such as Gunicorn to serve the app.  app.run(host='127.0.0.1', port=8080, debug=True)@app.errorhandler(500)def server_error(e):  return 'An internal error occurred [main.py] %s' % e, 500


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/648373.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号