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 %}
                    <img class="container-images-image" src={{ 
*STATIC_PREFIX* }}{{ item.image }}/>
                {% endfor %}

W dniu piątek, 5 lipca 2019 16:22:22 UTC+2 użytkownik John Bagiliko napisał:
>
> Remove the upload_to in the model.
>
> On Fri, Jul 5, 2019, 12:55 PM Michał Ratajczak <luminous...@gmail.com 
> <javascript:>> 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 = models.ImageField(upload_to='media/', null=True, blank=True)
>>
>>
>> in settings.py:
>>
>> STATIC_URL = '/static/'
>> MEDIA_URL = '/media/'
>>
>> ENV_PATH = os.path.abspath(os.path.dirname(__file__))
>> STATIC_ROOT = os.path.join(ENV_PATH, '../public/static/') 
>> MEDIA_ROOT = os.path.join(ENV_PATH, '../public/media/')
>>
>> in urls.py:
>>
>> urlpatterns = [
>>     path('admin/', admin.site.urls),
>>     path('', include('barber.urls'))
>> ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
>>
>> in view.py:
>> def index(request):
>>     images = Question.objects.values('image')
>>     template = loader.get_template('barber/index.html')
>>     context = {
>>             'images': images
>>         }
>>     return HttpResponse(template.render(context, request))
>>
>> I'am adding an image via admin site and next i render in template. Url 
>> for image is "media/image.png" bit file is in .../media/media/image.png, so 
>> i can't understand it. Can anyone help me ?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/5613b376-575f-4ab0-bdff-368f0fe8f1cf%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/5613b376-575f-4ab0-bdff-368f0fe8f1cf%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db65491a-9c80-4809-a6b5-9a29c23e6427%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to