Django管理员查看上传的照片 [英] Django admin view uploaded photo
问题描述
我已经在Django中实现了照片上传,但是在查看Django管理员时遇到了问题.
models.py
Class WorkPlacePhoto(models.Model):文件=模型.FileField(存储= FileSystemStorage(位置= settings.MEDIA_ROOT),upload_to ='上传')
照片保存在 PATH_TO_APP/media/uploads/
中,我可以在我的应用程序中查看它们.但是,在管理面板中,当我单击生成管理应用程序的链接时,它给我404错误,
请求方法:GET要求网址:http://127.0.0.1/admin/wpphotos/workplacephoto/9/media/uploads/aosa_glb_ho_778_hi.jpg/找不到u'9/media/uploads/aosa_glb_ho_778_hi.jpg'对象
尽管消息很清楚,但我无法弄清楚应该写哪个url来查看图像,当然也不能弄清楚如何修改admin类.
我很高兴为我建议实现这一目标的方法.谢谢...
根据您的描述,我猜您是静态文件文档,以获取有关如何通过Django开发服务器提供图像的灵感.
I have implemented photo upload in Django but I have a problem to view it Django admin.
models.py
class WorkPlacePhoto(models.Model):
file = models.FileField(storage=FileSystemStorage(location=settings.MEDIA_ROOT), upload_to='uploads')
Photos are saved in PATH_TO_APP/media/uploads/
and I can view them in my app. However, in admin panel, when I clicked on the link which admin app is generated it gives me 404 error as
Request Method: GET
Request URL: http://127.0.0.1/admin/wpphotos/workplacephoto/9/media/uploads/aosa_glb_ho_778_hi.jpg/
u'9/media/uploads/aosa_glb_ho_778_hi.jpg' object is not found
Although the message is clear, I couldn't figure out which url should be written to view the image and of course how admin class should be modified.
I glad to suggest me a way to achieve this. Thanks...
From you description I am guessing your MEDIA_URL isn't set correctly, something which is a bit tricky to do using the Django development web server.
I am guessing that the link's href would probably be media/uploads/aosa_glb_ho_778_hi.jpg
where you probably want /media/uploads/aosa_glb_ho_778_hi.jpg
so it is relative to http://127.0.0.1/
not to where you happen to be now http://127.0.0.1/admin/wpphotos/workplacephoto/9/
.
See the static files documentation for inspiration of how to serve your images with the Django development server.
这篇关于Django管理员查看上传的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!