在Django模板中包含图像文件是否显示断开的链接? [英] include image files in Django templates shows broken link?

查看:85
本文介绍了在Django模板中包含图像文件是否显示断开的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部

我已经尝试了提示在论坛上.不幸的是我仍然被困住. 该图像未出现在模板中. 据我所跟踪的错误,现在它们是双重的:

I've tried the tips found on the forum. Unfortunately i'm still stuck. The image doesn't appear in the template. As far as i've traced the errors now they are twofold:

1)应该在其中显示图片的位置仍然有断开的链接和错误消息:

1) one where the picture should appear there is still a broke link and an error message:

Failed to load resource: the server responded with a status of 404 (NOT FOUND),
**http://127.0.0.1:8000/Point3D/grafiek/laptop.jpg**

因此它确实走在正确的路径上,但是找不到图像..这在我的MEDIA_ROOT中 否则我会收到:

So it does go in the right path, but can't find the image.. Which is in my MEDIA_ROOT or I receive:

Resource interpreted as image but transferred with MIME type text/html with:
**http://127.0.0.1:8000/Point3D/grafiek/**

2)另一个错误是,如果我转到:http://127.0.0.1:8000/media/我得到:

2) The other error is that if i go to : http://127.0.0.1:8000/media/ i get:

Permission denied: /media/

也许这与它有关.

对于其余部分,我一直遵循罗伯茨解决方案暂时没有任何运气.

For the rest i've followed roberts solution for now but without any luck..

任何帮助将不胜感激!

推荐答案

/media/上的权限被拒绝恰恰是应该发生的情况,因为否则您页面的每个用户都可以查看该目录中的所有文件(与将Apache配置为允许目录建立索引(在大多数情况下不是您想要的)相同,请尝试通过粘贴完整的URL(并在路径中包括媒体URL)来在浏览器中访问文件: /p>

Permission denied on /media/ is exactly what is supposed to happen, as otherwise every user of you page could view all the files in that directory (Would be the same as configuring Apache to allow Indexing of a Directory, which is, in allmost al cases, not what you want. Try accessing the file in your browser by pasting the complete url, (and include the media url in your path!):

http://127.0.0.1:8000/media/Point3D/grafiek/laptop.jpg

如果这不起作用,请确保已将Django或Apache配置为提供您尝试访问的静态文件.

If that does not work, make sure you have Django or Apache configured to serve the static files you try to access.


还有可能导致您麻烦的一件事:/media/是管理媒体URL的默认设置.如果您的管理媒体网址和您的媒体网址相同,那就不好了.进行更改,以使您的MEDIA_URL和ADMIN_MEDIA_PREFIX不相同.

edit:
And one more thing that could cause your trouble: /media/ is the default for the admin media url. If your admin media url and your media url are the same thats no good. Change that so your MEDIA_URL and your ADMIN_MEDIA_PREFIX are not the same.

这篇关于在Django模板中包含图像文件是否显示断开的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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