0👍
✅
LeaveSTATIC_ROOT
empty.
Add this in STATICFILES_DIRS
:
os.path.join(PROJECT_ROOT, 'static/')
Make sure the upper code contains: /project_root/project/static
In urls.py remove these useless lines:
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += staticfiles_urlpatterns()
Run ./manage.py collectstatic
Should work.
Edit:
Since you have already done {% load static %}
you don’t need to do {{ STATIC_URL }}/..
{% load staticfiles %}
<img src="{% static "my_app/myexample.jpg" %}" alt="My image"/>
will work.
1👍
Please note this answer doesn’t apply if you are using the internal django development server.
Have you added an alias for /static/
in your Apache setup? If not, any calls to that folder will result in a 404 error, meaning your CSS won’t load. Here is an example of what I mean:
<VirtualHost *:80>
ServerName www.example.com
WSGIScriptAlias / "/path/to/project/project/wsgi.py"
DocumentRoot "/path/to/project"
<Directory "/path/to/project">
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
Alias /media/ "/path/to/project/media/"
<Directory "/path/to/project/media/">
Order deny,allow
Allow from all
</Directory>
Alias /static/ "/path/to/project/static/"
<Directory "/path/to/project/static/">
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
- [Answer]-Django Postgres database records reordering
- [Answer]-Why does my query in views.py give me a a TypeError?
Source:stackexchange.com