![](/img/trans.png)
[英]Django: Page not found , Raised by:django.views.static.serve
[英]page not found django.views.static.serve
第一次发帖,所以要温柔。
我正在尝试在 django 中显示静态图像。 我可以将图像上传到我的媒体目录,但是当我尝试显示它时,我什么也没有。 如果我将网址复制到浏览器,我会得到...
页面未找到 (404) 请求方法:GET 请求 URL: http : //127.0.0.1 :8000/media/Will_and_Matt.jpg 提出者:django.views.static.serve
详细信息
...
<img src="{{ student.photo.url }}" class="img-responsive">
...
模型.py
class Student(models.Model):
photo = models.FileField( blank=True, null=True)
项目网址.py
from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^opencmis/', include('opencmis.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_URL)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_URL)
设置.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
我的更新表单在创建媒体文件夹并将图像放入其中时起作用。
URL 模式似乎与 /media 匹配,因为它没有给出错误,只是不显示图像。
有什么想法吗?
document_root=settings.STATIC_URL
应该是document_root=settings.STATIC_ROOT
和MEDIA_ROOT
类似。 你想要文件系统路径在那里,而不是 URL。
– dhke
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.