1

In my settings I have

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

my uploaded files are saved in media folder..

In my template now I want to access these files

<img src="{{MEDIA_URL}}{{file.my_file}}" width="100" height="100" /></a>

When I do this its not showing the images or file.How can I get the file.. What should I use ?

gamer
  • 5,673
  • 13
  • 58
  • 91
  • {{file.my_files}} give the image from context. doing not giving the image so – gamer Mar 27 '15 at 16:04
  • you should look at this doc https://docs.djangoproject.com/en/dev/howto/static-files/ – CY5 Mar 27 '15 at 16:05
  • If you inspect the image path that is being generated in your browser's console, what does it say? – Aaron Lelevier Mar 27 '15 at 16:31
  • What does your `urls.py` look like? Make sure you have the following set `if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ` – Staccato Nov 23 '19 at 10:57

1 Answers1

1

what i have set in settings.py: MEDIA_ROOT = '/home/paulius/django-paulius/epc/static/'

there i have several folders for my static files. one of them is for uploaded files. in my template i would write: <p><a href="/static/assets/{{patient.thumbnail}}">FILE</a></p>

this one works. i am using it right now. try checking the url to your files, maybe you misprinted something

pptt
  • 675
  • 2
  • 8
  • 16