我给我的“滴扬戈”模式增添了一个新特征,其中包括一个形象地特征:
模型.py:
class AvailableDrinks(models.Model):
drink_name = models.CharField(max_length=200)
store_name = models.ForeignKey( Stores , on_delete=models.CASCADE,)
description = models.CharField(max_length=1200)
drinksSlug = models.SlugField(unique=True, null=True)
photo = models.ImageField(upload_to="static/media/images/drinkPhotos", blank=True)
def __str__(self):
return self.drink_name
意见:
class DrinksView(generic.DetailView):
template_name = "drinks.html"
context_object_name = "drinks"
model = AvailableDrinks
slug_url_kwarg = drinksSlug
def get_object(self):
return get_object_or_404(AvailableDrinks, drinksSlug=self.kwargs[ drinksSlug ])
def get_queryset(self):
return AvailableDrinks.objects.all()
class StoreView(generic.DetailView):
template_name = "caffeine-stores.html"
model = Stores
context_object_name = stores
slug_url_kwarg = slug
Url.py:
urlpatterns = [
path("", HomeView.as_view(), name="home"),
path( <slug:slug>/ , StoreView.as_view(), name="stores"),
path("<slug:slug>/<slug:drinksSlug>/", DrinksView.as_view(), name="drinks"),
path("<int:account_id>/select_drinks/", views.select_drink, name="select")
]
print(settings.DEBUG)
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Settings.py:
STATIC_URL = static/
MEDIA_URL =
MEDIA_ROOT = BASE_DIR
我已经印刷了我的节目,以确保这些节目能够适当贴上影像档案。 我也保证,他们正在从行政网页上正确上载荷,但我仍然有错误:“GET /static/media/images/dnas Phitos/icepo_dcc.jpeg ÜTP/1.1” 404 1888。 我只是略微失踪了? 最初,我收到一个档案错误,说没有与影像场有关的档案,但我用一些私利 around。 如今,网站显示,但图象回头看,没有显示。