G
G
GadZini2014-12-05 01:19:34
Django
GadZini, 2014-12-05 01:19:34

How to upload pictures from the media folder?

How to load images from the media folder in Django (they are not saved to the database and not cached) on mouse click or from the admin interface.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya, 2014-12-05
@FireGM

If you just need access to files from django that are in the media folder, then https://docs.djangoproject.com/en/dev/howto/static...
Same thing, but in Russian
djbook.ru/rel1.7/ howto/static-files/index.html#ser...
If on production, then some kind of nginx
But I don’t quite understand why files are needed in the media folder, but their path is not stored anywhere O_o

A
Ali Aliyev, 2014-12-05
@ali_aliev

for local development in urls.py

from django.conf.urls.static import static
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

both static and media will work
for production, of course, the path in nginx to the static and media directories

K
k-maks, 2014-12-10
@k-maks

What does it mean to upload images?
You can print a list of them and do whatever you want with it:

import os
from django.template import RequestContext
from django.conf import settings
from django.shortcuts import render_to_response
def view(request):
  media_files = [ f for f in listdir(settings.MEDIA_ROOT) if isfile(join(settings.MEDIA_ROOT,f)) ]
  ...
  return render_to_responce('media_index.html',{'files':media_files},context_instance=RequestContext(request))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question