Answer the question
In order to leave comments, you need to log in
Why in django I have a 404 error instead of an image?
Good afternoon! Here is the thing, I upload the image to the server and also the link to the image in the database
And I prepare it for uploading in the admin panel in the form of a preview
def make_path(instance,filename,prefix=False):
n1 = random.randint(0,10000)
filename = str(n1)+".jpg"
return u"%s/%s" % (settings.IMAGE_DIR, filename)
class Content(MPTTModel):
image = models.ImageField(upload_to=make_path, default="", blank=True, verbose_name="Изображение")
def pic(self):
if self.image:
return u'<img src="%s" width="170"/>' % self.image.url
else:
return '(none)'
#settings.py
IMAGE_DIR = "img"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question