如何在Django中访问媒体文件 [英] How to access media files in django

查看:72
本文介绍了如何在Django中访问媒体文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的设置中,我有

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 ?

推荐答案

我在settings.py中设置的内容: MEDIA_ROOT ='/home/paulius/django-paulius/epc/static/'

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

我的静态文件有几个文件夹.其中之一是用于上传的文件.在我的模板中,我会写:< p>< a href ="/static/assets/{{Patient.thumbnail}}"> FILE</a></p>

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

这篇关于如何在Django中访问媒体文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆