简体   繁体   English

找不到Django媒体页面404

[英]Django media page not found 404

I'm trying to learn to work with Django and i'm making a image app. 我正在尝试学习与Django一起工作,并且正在制作图像应用程序。 Now I managed to upload images to my database, but now I want to retrieve them. 现在,我设法将图像上传到我的数据库中,但是现在我想检索它们。

The images are stored in media/images/ . 图像存储在media/images/

Now I made an admin page that looks like this: 现在,我创建了一个管理页面,如下所示:

在此处输入图片说明

AS you can see the thumbnails don't load. 如您所见,缩略图没有加载。 When You click on one of those thumbnails, I get the following error: 当您单击这些缩略图之一时,出现以下错误:

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/media/images/june.png
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, media/images/june.png, didn't match any of these.

Here is my urls.py of my main thinghy (not the app, wich is called photo): 这是我主要内容的urls.py(不是应用程序,被称为照片):

from django.conf.urls import patterns, include, url
from django.contrib import admin

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),

)

Now I'm not sure what I exactly need to do to fix this. 现在,我不确定要解决此问题到底需要做什么。 I hope you can help me. 我希望你能帮助我。 Please be clear ( small steps ) cause I'm not that experienced with django. 请明确说明(小步骤),因为我对django并不了解。

Thanks in advance 提前致谢

Oh BTW i'm on Win7 哦,顺便说一句,我在Win7上

EDIT: 编辑:

this is what I added to my settings/py 这就是我添加到settings/py

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

MEDIA_URL = '/http://127.0.0.1:8000/media/'

So right now, your urls.py doesn't have a pattern for /media/images. 因此,目前,您的urls.py没有用于/ media / images的模式。 That pattern probably exists somewhere in your photo app. 该模式可能存在于您的照片应用程序中的某处。 You need to link the urls for your photo app into your primary urls.py, something like: 您需要将照片应用的网址链接到主urls.py中,例如:

url(r'^media/', include('photo.urls')),

This would tell the app that if it sees a url with media/ it should look for the next thing ('images/') in the photo app. 这将告诉应用程序,如果它看到带有media /的URL,则应在照片应用程序中查找下一个内容(“ images /”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM