Home > OS >  Loading static file to a css file django-python
Loading static file to a css file django-python

Time:07-30

I have a css file and I want to link another static file to it.How can I accomplish this

@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"

Both {% load static %} and {% load staticfiles%} are not working

CodePudding user response:

Template filters and tags only work in HTML files that are rendered in Django views. In static files (CSS, JS etc.) you have to use hard-coded absolute path.

CodePudding user response:

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

OR

Django also provides a mechanism for collecting static files into one place so that they can be served easily. 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. So when we run python manage.py collectstatic, gather all static files into a folder called staticfiles in our project root directory.

  • Related