Reputation: 8791
I'm trying to use an image in my local server in a html file. But the image is not found.
This is the path for the image(copy and paste from Mac Get Infor): /Users/filipeferminiano/Pictures/teste.jpg
And my code:
I'm using Django.
This are my settings:
STATIC_ROOT = os.path.join(PACKAGE_ROOT, "static", "static-only")
STATIC_URL = "/static/static-only/"
STATICFILES_DIRS = [
os.path.join(PACKAGE_ROOT, "static"),
]
Upvotes: 0
Views: 135
Reputation: 66
you shoud define MEDIA_ROOT in your settings file:
MEDIA_ROOT = (os.path.join(os.path.dirname(__file__), '..', 'appl_name/Static').replace('\\', '/'))
your images must be in appl_name/Static/Pictures/ dir
you template should look like this:
{% load staticfiles %}
<img src = {% static 'Pictures/teste.jpg' %} />
Upvotes: 1
Reputation: 1
In your base folder for your django project you usually want to have a "media" or "static" folder. Here you will save your images. Then in settings.py define STATIC_ROOT = 'static' . define STATIC_URL = '/static/' . and finally in your HTML IMG tag define it as such <img src="{% STATIC_URL %}example_image.jpg >
. that should work n fix ur image problem.
Upvotes: 0