I have Django 4.1.7 website, served by apache2 on Ubuntu PC.
in the .conf file of apache2: Alias /static /mnt/hdd/SIMSY/static/
and Django works as expected.
All CSS, JS, Images are loaded just fine.
But when adding new object using Django's built-in admin site, the site tries saving the images on /static
in the root of Ubuntu (it caused Permission error, then I tried creating that folder in the root and it actually saved the image in that folder).
How is Django trying to save in /static
while apache2 tells it that /static
is /mnt/hdd/SIMSY/static
?
I assume there is something can be changed in settings.py to solve that, what can be changed?
Here is the part of settings.py that has anything to do with static:
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATICFILES_DIRS = [
BASE_DIR / "static",
]
Uploading files are not static files. These are media files. You need to set MEDIA_ROOT and MEDIA_URL in your settings file to handle them properly.
Here are some more useful links on how to handle user uploaded files in django: