【问题标题】:The names of static files are specified without the static url指定静态文件的名称,不带静态 url
【发布时间】:2016-10-05 22:57:02
【问题描述】:

姜戈。静态文件的名称是在没有静态 url 的情况下指定的。 示例:<img src="my.png" /> 怎么做?谢谢!

【问题讨论】:

  • 到目前为止,您尝试了什么,遇到了什么问题?

标签: django


【解决方案1】:

假设您需要在模板中正确设置静态文件(即它们由 nginx/apache 为您提供,或者您使用 DEBUG=True 运行),您需要

{% load staticfiles %}
{% static "path/under/your/static/file/folder.gif" %}

如果这是您正在做的事情并且它不起作用,那么您的 STATIC_URL、STATIC_ROOT 等可能不正确。

【讨论】:

    【解决方案2】:
    {% load static from staticfiles %}
    {% static "/challenge.x.png" as mono %}
    <img src="{{mono }}"
    

    返回&lt;img src="/static/challenge.x.png" /&gt;

    正确的是&lt;img src="challenge.x.png" /&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-11
      • 2014-06-22
      • 2019-03-05
      • 2014-10-17
      • 2020-01-19
      • 1970-01-01
      • 1970-01-01
      • 2014-09-21
      相关资源
      最近更新 更多