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'
> inside the media folder.
>
> On Fri, Jul 5, 2019, 2:21 PM John Bagiliko <john.bagil...@aims-senegal.org>
> wrote:
>
>> Remove the upload_to in the model.
>>
>> On Fri, Jul 5, 2019, 12:55 PM Michał Ratajczak <
>> luminousshado...@gmail.com> 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-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/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/CAC26BE1jsSya48W0dUgag8XW0eDLjbBjpZW8Ap97mRhq8geNgA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAC26BE1jsSya48W0dUgag8XW0eDLjbBjpZW8Ap97mRhq8geNgA%40mail.gmail.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/CAAmw3B329myWM_WCUOs9KDGG50bnqr0KbaysNLfJ-s-xeP10rg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to