Heroku Flask部署中未显示背景图像

时间:2020-05-06 04:35:21

标签: html css heroku

摘要: 我有一个html页面,在本地看起来不错,但是当我将其部署到heroku时,背景图像丢失了。

我尝试过的事情: 我当前正在使用属性background-image: url(bg.jpg);

我也尝试过image-url(bg.jpg)asset-url(bg.jpg)(在本地均不工作)。

我已阅读的内容: 据我了解,有几种可能性

  • 设置config.serve_static_assets = true
  • 设置config.assets.compile = true

我不太了解如何设置这些设置?我一直看到引用了“ production.rb文件”,但我不知道这是什么吗?我可以在heroku仪表板中设置这些属性吗?

当前,我只是将代码推送到GitHub并从那里进行部署。我是Heroku的新手,而且是一般的部署人员,在此主题上提供的任何帮助将不胜感激。

procfile

web: gunicorn app:app

文件结构

procfile
requirements.txt
app.py
templates
  |- index.html
  |- positive.html
  |- negative.html
  |- bg.jpg

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题。我现在意识到,因为这是一个Flask应用程序,因此需要以不同的方式进行处理。

以下更改将纠正该错误:更改文件结构以将图像放入静态文件夹(Flask知道要查找此文件夹),然后更改url调用。

文件结构

procfile
requirements.txt
app.py
static
  |- img
      |- bg.jpg
templates
  |- index.html
  |- positive.html
  |- negative.html
  |- bg.jpg

background-image: url('/static/img/bg.jpg');

我不确定为什么这可以解决问题,但是可以解决问题!