简体   繁体   中英

Upload file django admin

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?

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/'

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/'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM