Answers for "image url django"

0

image url django

This setup is working for me, maybe it will help you. It is for latest version of Django. Many answers in OS are for older Django versions.

URLS:

urlpatterns = [
#url
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Settings:

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
Template:

<img src="{{ foo.image.url }}"><br>
Model:

image = models.ImageField(upload_to = 'img/', default = 'img/None/no-img.jpg')
My foo model has an imagefield, when it is stored, I can retrieve the full url through item.image.url based on the above setup.
Posted by: Guest on March-17-2021

Python Answers by Framework

Browse Popular Code Answers by Language