[英]How to use angular build assets inside python flask static?
我正在研究在前端使用angular7并在后端使用python flask框架的应用程序。 我正在尝试采用角度构建,即dist文件夹,并根据烧瓶结构在烧瓶中进行配置。
我无法在该服务器上加载图像。 dist中的图像路径类似于dist/assets/images
。
flask
---app.py
---templates
----index.html
---static
---- main6gaugsx.js
---- runtime7gyg.js
--conf files
我试图将这些图像移动到flask的静态文件夹中。 但是我无法在main6gaugsx.js
设置图像的路径,因为它是捆绑的代码。 此外,图像可能会在以后增加时间点。 每次部署时,我都无法更改。
但是问题是index.html
也将放置在static
文件夹中,而不是模板文件夹中。 为了解决这个问题,在Flask app
创建过程中将template_folder
设置为static/build
或将index.html
放置在static
文件夹中的任何位置。
# assuming, the angular build is in the statis/build directory
app = Flask(__name__, static_folder='static', template_folder='static/build`)
我将角度构建outputPath更改为指向静态文件夹。
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "my-project/dist/static",// changes
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/assets",
"src/favicon.ico"
],
},
.
.
},
将构建静态文件夹移动到服务文件中,并如下更新main.py中的static_folder和template_folder路径。
cp -r angular/my-project/dist/static service/app
在main.py中。
app = Flask(__name__, static_folder='static', template_folder='static')
@app.route('/')
def home():
return render_template('index.html')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.