如何使用 Web2py 中数据库中的 img 文件更改背景图像 [英] How to change the background image using img file from database in Web2py
问题描述
我想要做的是使用上传到数据库中而不是 'static', 'images'
文件夹中的图像文件来不断更改背景图像.
What I am trying to do is to keep changing the background image using image files that are uploaded in the database instead in the 'static', 'images'
folder.
我显然不能在 css
中做到这一点,实际上,我不确定这是否可能.我可以在 layout.html
或 View
中以某种方式完成这项工作吗?
I obviously can't do this in the css
, actually, I am not sure if this is even possible. Can I make this work in the layout.html
or in the View
somehow?
如果不是背景图像,我将在 View
中显示图像:
This is how I would display an image in the View
if it wasn't intended to be a background-image:
<img src="{{=URL('download', args=pic_row.pics)}}"/>
当然,这种显示背景法师的方法是行不通的:
Of course, this approach to display a background-mage won't work:
<section id="main" class="main row" style="background-image:{{=URL('download', args=pic_row.pics)}}">
..但是有没有办法让我真正做到这一点?
..but is there a way I can actually achieve this?
推荐答案
<section id="main" class="main row" style="background-image:{{=URL('download', args=pic_row.pics)}}">
问题中提出的上述方法很接近,但是CSS语法不正确.style
属性应该是:
The above method proposed in the question is close, but the CSS syntax is incorrect. The style
attribute should be:
"background-image: url('{{=URL('download', args=pic_row.pics)}}')"
这篇关于如何使用 Web2py 中数据库中的 img 文件更改背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!