【问题标题】:Loading Django static files into css styles将 Django 静态文件加载到 css 样式中
【发布时间】:2020-12-09 19:58:47
【问题描述】:

这是我在问题中所指的部分:

<div class="my-class" style="background: url({% static 'no_profile_pic/no-profile-pic.png' %}) center / cover no-repeat;"></div>

它正在寻找它:

[20/Aug/2020 12:54:30] "GET /static/no_profile_pic/no-profile-pic.png HTTP/1.1" 200 41235

但是,它没有加载到我的网页上。

我的 html 文件中有 {% load static %}

这是我的设置文件:

STATIC_URL = '/static/'

STATICFILES_DIRS = [

    os.path.join(BASE_DIR, "static"),
]

有什么想法吗?

【问题讨论】:

    标签: css django bootstrap-4 static django-templates


    【解决方案1】:
    <div class="my-class" style="background: url({% static 'no_profile_pic/no-profile-pic.png' %}) center / cover no-repeat;"></div>
    

    问题来了。就这样写吧,url('no_profile_pic/no-profile-pic.png') 你会很高兴的。

    【讨论】:

    • 感谢您的回复。不幸的是,我尝试过没有运气。我得到:未找到:/no_profile_pic/no-profile-pic.png [20/Aug/2020 13:19:05] "GET /no_profile_pic/no-profile-pic.png HTTP/1.1" 404 12362
    • 哦,我很抱歉,但惯例是像上面那样写......也许还有一些其他问题需要调试......
    • 令人尴尬的答案,但我加载了错误的 css 文件!仍然感谢 djangotic 的响应。
    猜你喜欢
    • 2020-08-31
    • 1970-01-01
    • 2020-04-28
    • 2022-01-20
    • 2011-11-26
    • 1970-01-01
    • 2017-10-08
    • 2015-09-11
    • 2021-06-09
    相关资源
    最近更新 更多