这是views.py:
class AnimeDetailView(DetailView):
model = AnimeDetail
template_name = 'anime_detail.html'
context_object_name = 'anime'
slug_field = 'name'
这是models.py:
class AnimeDetail(models.Model):
name = models.CharField(max_length = 256)
type = models.CharField(max_length = 100, choices = (...))
anime_classification = models.CharField(max_length = 256, n
ull = True)
story = models.TextField()
anime_relase = models.DateField()
rate = models.FloatField(null = True)
photo = models.ImageField(upload_to = 'anime/static/photo')
这是urls.py
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.STATIC_URL, document_root = settings.STATICFILES_DIRS)
这是setting.py:
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
这是template.html:
<img src="{{ anime.photo }}"/>
图像“ anime / static /”的路径,但是在终端中我得到了“ GET /anime/anime20%name/anime/static/photo/x.jpg HTTP / 1.1” 404 2933 “