0

I save path of image in database like 'Image/upload/imageOne.jpg' and Image folder in static directory then i want to show this image in html with this tag:

<img src="{% static '{{ product.productImagePath }}' %}" alt="{{ product.productName }}" width="800px" height="300px">

but i have error and can not find path and just show alt how can fix it? Thanks for help

4 Answers 4

1

try this

{% load static %}

<img src="{% get_media_prefix %}{{ product.productImagePath }}" alt="{{ product.productName }}" width="800px" height="300px">
Sign up to request clarification or add additional context in comments.

Comments

0

Try without static:

<img src="{{ product.productImagePath }}" alt="{{ product.productName }}" width="800px" height="300px">

6 Comments

What is in product.productImagePath ? Are you sure it is not empty ?
So what is there ? Try to print it.
when i try to print in browser i see 'Image/upload/imageOne.jpg' i am use mongodb and send address of image in dictionary
Ok. So, check if your static folder is correct. What error do you get, when you inspect the element(in the browser console) ?
try to add .url at the end: src="{{ product.productImagePath.url }}"
|
0

assuming your serving your page using apache, make sure the image directory is also located in the 'www' folder other wise it cant be access without changing your httpd config, other servers might auto direct to 'htdocs' folder.

Reading this Djanjo doc might help You:

https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/#serving-files

2 Comments

i use local host for design and test website in this project i want to use mongodb database and save path in database but i can not use this path in html page
@user7456254, you need to configure apache or a webserver to allow this, read this article: docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/…
0

Specify the static folder path correctly in settings.py. run the command python manage.py collectstatic from the location of manage.py . It will copy the static image file from your folder to root static folder. Then when you refresh the page you can see the changes there. Refer in this link to do settings. https://docs.djangoproject.com/en/1.11/howto/static-files/

1 Comment

thanks for your help but i can use normal method in this project because i use noSQL (mongoDB) and i cant save image in database i can save just path of image in folder and recovery image with this path but i can do this and i have problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.