How to add css, js or other local files in Django project ?

0
0

First of All put these lines into settings.py file:

STATICFILES_DIRS = [
os.path.join(BASE_DIR, ‘latest/static/’)
]
STATIC_ROOT = os.path.join(BASE_DIR, ‘static’)
STATIC_URL = ‘/static/’

then write:

python manage.py collectstatic 

it will bring all of your css and js files into your project root directory.

And Then open up your any template file and go to the <html> element, then write this line of code below <html> tag:

{% load staticfiles %}

Now you can access any local static file using this code:

{% static ‘admin/css/base.css’ %}

Example:

<link rel=”stylesheet” type=”text/css” href=”{% static ‘admin/css/base.css’ %}”>

 

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.