66π
β
For the directory structure like so,
-- static
|--fonts
| |--abc.ttf
|
|--css
|-- main.css
In the main.css
, you should add.
@font-face {
font-family: 'abc';
src: local('Abc'),
url('../static/fonts/abc.ttf') format("truetype");
}
You canβt use {% static 'filename' %}
inside a css file, since it will not be rendered by the django templating engine.
Also, if you want you can add the following in the <head>
section of base.html
, and it will render a fully qualified path for static assets:
<style>
@font-face {
font-family: 'abc';
src: local('Abc'),
url('{% static 'fonts/abc.ttf' %} format("truetype")');
}
</style>
Edit: Fixed the use of local
and also removed the preference around location of style tag in html.
π€Saurabh Kumar
3π
I am using this option to avoid absolute path and/or css in html template:
@font-face {
font-family: 'HKGrotesk';
font-style: normal;
font-weight: bold;
src: local('HKGrotesk'), url('/static/fonts/hk-grotesk/HKGrotesk-SemiBoldLegacy.otf') format('opentype');
}
π€matousc
- [Django]-How to produce a 303 Http Response in Django?
- [Django]-Can't connect to local MySQL server through socket '/tmp/mysql.sock
- [Django]-How to set a value of a variable inside a template code?
Source:stackexchange.com