I’m not clear about what you’re looking for, but from
create image tags for every file in a directory located in static
I’m assuming that you’re looking to load image using the {% static %}
tag:
{% load static %}
...
<img src="{% static 'path_to_image' %}" alt="img1.jpg" height="100px" width="100px">
<!-- Watch out the single and double quotes -->
Do remember to include this in your settings.py
:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'), // or wherever you put your static files
]
I think it’s now automatic, but check your INSTALLED_APPS
:
INSTALLED_APPS = [
...
'django.contrib.staticfiles',
]
Compared to hard-coded paths like C:/foo/baz/bar/
, it’s better to load static tags because it always works on different platforms as every operating system has its own way to handle files, which I hope answers your question.