【发布时间】:2023-03-15 05:35:01
【问题描述】:
当数据库中的数据被序列化时,图像在 react 中停止显示,但 {product.image} 显示图像的路径。请我想知道为什么图像没有在反应中显示,但在 django 中运行良好。每当我单击管理页面中的图像链接时,都会显示产品。当从 django 将产品作为 python 数组获取时,显示的图像会做出反应,但是当我转向 drf 时,它会停止显示。我正在使用 Django 4.0,我不知道这是否对这个问题有任何影响。使用 DRF 时,除图像外,产品的所有其他属性都会以反应方式显示
Here's the part of the React component where the image is referenced
<Link to={`/product/${product._id}`}.
<Card.Img src={product.image} />
</Link>
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('base.urls'))
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
STATIC_URL = 'static/'
MEDIA_URL = '/images/' STATICFILES_DIR = [ BASE_DIR / 'static' ]
MEDIA_ROOT = 'static/images
【问题讨论】:
-
你能告诉我们产品序列化器吗?一般来说,检查图像字段是否包含在其中或错误地将其放入排除列表中
标签: reactjs django django-rest-framework