Reputation: 343
I'm creating a admin form where users can upload files. I want this to be stored in a secure place where the public can't get it. I'm using a standard form with a FileField
and no model. Is there a way I can store the files in a folder within the app folder?
Upvotes: 0
Views: 527
Reputation: 118
Yes you can do this
Add these line in your project level file urls.py(which is auto generated when project is created)
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
And add these lines in your settings.py
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
Upvotes: 1
Reputation: 1001
Yes you can do that by specifying the path in your settings.py file eg. MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
Upvotes: 1