[Answer]-Fetch Static files from Server in Django

1👍

this is the url of the static that will be used in template STATIC_URL = '/static/'

add the desire path to the static files dirs var


STATICFILES_DIRS = ('/var/www/my_site/my_path',)

please note that the path doesn’t end with backslash

please note that the trailing comma

now in your templates use

<head>
    {% load staticfiles %}
    <link href="{% static "css/style.css" %}" rel="stylesheet">
</head>

this link will resolve to my_site/static/css/style.css
and will be in the folder /var/www/my_site/my_path/css/style.css

href="my_site/static/css/style.css"
maps to

STATICFILES_DIRS : /var/www/my_site/my_path/css/style.css

👤a14m

Leave a comment