简体   繁体   English

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

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

I have a css file and I want to link another static file to it.How can I accomplish this我有一个 css 文件,我想将另一个 static 文件链接到它。我怎样才能做到这一点

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

how can I load this "font/static-mobile.woff"我怎样才能加载这个“font/static-mobile.woff”

Both {% load static %} and {% load staticfiles%} are not working {% load static %} 和 {% load staticfiles%} 都不起作用

Template filters and tags only work in HTML files that are rendered in Django views.模板过滤器和标签仅适用于在 Django 视图中呈现的 HTML 文件。 In static files (CSS, JS etc.) you have to use hard-coded absolute path.在 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 and also we must tell Django to also look for static files in a folder called static in our root directory 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 文件

OR或者

Django also provides a mechanism for collecting static files into one place so that they can be served easily. Django 还提供了一种机制,用于将 static 文件收集到一个位置,以便轻松提供它们。 Using the collectstatic command before using the collectstatic command create a STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') Django looks for all static files in your apps and collects them through the STATIC_ROOT.在使用 collectstatic 命令之前使用 collectstatic 命令创建一个 STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') Django 在您的应用程序中查找所有 static 文件并通过 STATIC_ROOT 收集它们。 So when we run python manage.py collectstatic, gather all static files into a folder called staticfiles in our project root directory.因此,当我们运行 python manage.py collectstatic 时,将所有 static 文件收集到项目根目录中名为 staticfiles 的文件夹中。

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

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