将模型变量传递给样式html标记Djang中background属性中的url()

2024-10-05 13:15:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将静态图像的位置传递给jumbotron div标记的style属性中包含的背景图像的url()属性。你知道吗

我尝试了以下几种不同的方法:

这是在我的公园里_详细信息.html你知道吗

{% extends 'full_base.html' %}
{% load tags %}
{% load static %}

{% block main_content %}
<div class = "jumbotron" style ="background-image:linear-gradient(rgba(255,255,255,.6), rgba(255,255,255,.6)), url({% static {{park.imageloc}} %});background-size:100%;background-position:left center; background-repeat:no-repeat">

此尝试返回错误:

TemplateSyntaxError at /waittimes/park/2/
Could not parse the remainder: '{{park.imageloc}}' from '{{park.imageloc}}' 

我也试图以此作为底线:

<div class = "jumbotron" style ="background-image:linear-gradient(rgba(255,255,255,.6), rgba(255,255,255,.6)), url({% static '{{park.imageloc}}' %});background-size:100%;background-position:left center; background-repeat:no-repeat">

在以下位置找不到图像:

/static/%7B%7Bpark.imageloc%7D%7D

提前谢谢


Tags: 图像divurlpark属性stylehtmlload
1条回答
网友
1楼 · 发布于 2024-10-05 13:15:53

尝试:

{% static park.imageloc %}

例如:

<div class = "jumbotron" style ="background-image:linear-gradient(rgba(255,255,255,.6), rgba(255,255,255,.6)), url({% static park.imageloc %});background-size:100%;background-position:left center; background-repeat:no-repeat">

相关问题 更多 >

    热门问题