English 中文(简体)
Django 404图像
原标题:Django 404 image for profile picture
  • 时间:2023-12-15 01:47:06
  •  标签:
  • django

我给我的“滴扬戈”模式增添了一个新特征,其中包括一个形象地特征:

模型.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。 如今,网站显示,但图象回头看,没有显示。

问题回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签