2👍
This as per document,you can try like this
settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/var/www/static/',# Here you can mention your static directory
]
urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
in your template
{% load static %}
<img src="{% static "my_app/example.jpg" %}" alt="My image"/>
Store your static files in a folder called static in your app. For example my_app/static/my_app/example.jpg.
- [Answered ]-How can I create simple Django chat based on WebSockets with PostgreSQL database?
- [Answered ]-Writable nested Django serializer with string instead of dict
- [Answered ]-Limiting the number of displayed instances of a model in Django Admin
Source:stackexchange.com