You need {{ item.image.url }} on your template since you are iterating
through the context you passed in views. I'm sure you did something like
this in views
def home(request)
images = Your_model.objects.all()
context = {'images': images}
return render(request, 'path_to/your/template',
Oh yeah! That's it ! Big thank's for you :)
W dniu piątek, 5 lipca 2019 22:14:52 UTC+2 użytkownik Jani Tiainen napisał:
>
> Hi.
>
> What you did is correct and expected.
>
> Upload_to is relative path to MEDIA_ROOT in case of normal file upload
> backend. There are many others like S3.
>
> Now
Hi.
What you did is correct and expected.
Upload_to is relative path to MEDIA_ROOT in case of normal file upload
backend. There are many others like S3.
Now MEDIA_URL is absolute path of web server which points to MEDIA_ROOT. In
development you can use static file serving trick like you did.
I Remove upload_to and it still wasn't working and next i did in my
template.html:
{% get_media_prefix as *STATIC_PREFIX* %} <- i added this line because {{
item.image }} returns only 'image.jpg'. Now a url is correct :)
{% for item in images %}
{% endfor %}
I just find it really useful to save it in Google cloud
On Fri., Jul. 5, 2019, 8:25 a.m. John Bagiliko, <
john.bagil...@aims-senegal.org> wrote:
> Since you already configured static folder called media in settings.py, if
> you specifify upload_to='/media', Django will create a folder 'media'
>
Since you already configured static folder called media in settings.py, if
you specifify upload_to='/media', Django will create a folder 'media'
inside the media folder.
On Fri, Jul 5, 2019, 2:21 PM John Bagiliko
wrote:
> Remove the upload_to in the model.
>
> On Fri, Jul 5, 2019, 12:55 PM
Remove the upload_to in the model.
On Fri, Jul 5, 2019, 12:55 PM Michał Ratajczak
wrote:
> Hi, i'm new in Django, I'm trying to configure media files correctly.
>
> That's in my model.py:
>
> class Question(models.Model):
> description = models.CharField(max_length=200)
> image =
Hi, i'm new in Django, I'm trying to configure media files correctly.
That's in my model.py:
class Question(models.Model):
description = models.CharField(max_length=200)
image = models.ImageField(upload_to='media/', null=True, blank=True)
in settings.py:
STATIC_URL = '/static/'
8 matches
Mail list logo