-2

Is there a way to download files by an app's method and store in a folder like "/media/" (relative path in django app) that can be later accessed by staticfiles?

MorRich
  • 426
  • 2
  • 5
  • 15

1 Answers1

0

For storing your media files in a folder like /media, you can check this out since you are new to django.

Tango with Django Tutorial

This link is about setting the static and media files' directory. But if you feel like you don't understand them, Just start from the beginning.

For downloading a file, I can give you a small example.

import requests
def download_file(self,link):
    content = requests.get(link).content
    f = open('filename', 'wb')
    f.write(content)
    f.flush()
    f.close()

But if you don't know the basic concepts of Django, I'd recomment you to go with Tango with Django first.

Cagatay Barin
  • 3,428
  • 2
  • 24
  • 43
  • The download part is OK, but my problem is the following: * when I use STATIC_URL = '/static/' than it means that the files are at myproj/app/static/app/file.ext * and when I use MEDIA_URL = '/media/' it won't use either myproj/media nor myproj/app/media/app/file.ext Why is this, and is there an other way instead of MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media') ? – MorRich Mar 07 '16 at 20:59