I'm using a development server for django. I want to grab my static files from a server. htts://www.example.com/static

How do I do this in Django?

Currently I'm trying to to change the STATIC_URL from '/static/' , but it fails whenever I change it. By fail I mean that the html still loads, but the site can't access and load my static files.

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top