繁体   English   中英

将 static 文件加载到 css 文件 django-python

[英]Loading static file to a css file django-python

我有一个 css 文件,我想将另一个 static 文件链接到它。我怎样才能做到这一点

@font-face {
  font-family: 'tinymce-mobile';
  font-style: normal;
  font-weight: normal;
  src: url("fonts/tinymce-mobile.woff?8x92w3") format("woff"); 
}

我怎样才能加载这个“font/static-mobile.woff”

{% load static %} 和 {% load staticfiles%} 都不起作用

模板过滤器和标签仅适用于在 Django 视图中呈现的 HTML 文件。 在 static 文件(CSS、JS 等)中,您必须使用硬编码的绝对路径。

Go to your settings.py file there you will see STATIC_URL = '/static/' under it create a STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), ) The STATICFILES_DIRS tuple tells Django where to look for static files我们还必须告诉 Django 在我们的根目录中名为 static 的文件夹中查找 static 文件

或者

Django 还提供了一种机制,用于将 static 文件收集到一个位置,以便轻松提供它们。 在使用 collectstatic 命令之前使用 collectstatic 命令创建一个 STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') Django 在您的应用程序中查找所有 static 文件并通过 STATIC_ROOT 收集它们。 因此,当我们运行 python manage.py collectstatic 时,将所有 static 文件收集到项目根目录中名为 staticfiles 的文件夹中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM