Django Upload an Image

Hi,

I’m trying to upload an image on VS Code using Django. For some reason, I’m having trouble.

`

I put {% load static%} on top of the page

The image file is modpodge.jpg and it’s under the file static under another file img thus static/img

Please let me know if you know what’s wrong.

Thank you,

Hi Aimslee,

For the image to display make sure a couple of things are set right.

  • Ensure that the path to the image is correct relative to the STATIC_URL specified in your Django settings.
  • Make sure that your STATICFILES_DIRS and STATIC_ROOT are correctly configured.

Assuming everything in your settings is configured correctly, and the image modpodge.jpg is located at static/img/modpodge.jpg , you can display this image in your template using:
<img src="{% static 'img/modpodge.jpg' %}">

Hope this shades some light.

Happy Coding :hearts:.

1 Like

Thank you! You’re of great help!!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.