我试图使用django rest框架在我的api中使用图像,但仍然没有找到错误404页面。这是我的密码-

型号.py

class SampleModel(models.Model):
    text = models.CharField(max_length=100, null=True, blank=True)
    image = models.ImageField(upload_to='images/', null=True, blank=True)

序列化程序.py

class SampleSerializer(serializers.ModelSerializer):
    image = serializers.ImageField(max_length=None, use_url=True)

    class Meta:
        model = SampleModel
        fields = ['text', 'image']

视图.py

class SampleView(generics.ListAPIView, generics.CreateAPIView):
    queryset = SampleModel.objects.all()
    serializer_class = SampleSerializer

url.py

urlpatterns = [path('sample/', SampleView.as_view(), name='sample')]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

设置.py

STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, "assets")
MEDIA_URL = '/assets/'

我试着在谷歌上搜索解决方案,也尝试了一些东西,但我仍然得到同样的错误。 我试图创建另一个项目,并使用与上面相同的代码,但它仍然给我相同的错误

The error I get while accessing the file.