I’m using Django (Django 4.0.3.) with Apache2 to run a webserver and serving media locally.
Part of the site is a warehouse item tracker and is working fine, user can upload media (images) to items, categories etc and everything is displayed as expected.
The other part displays multiple images downloaded from an ftp server via a script I wrote in python, which downloads images, stores them in its specific folder (in the media folder) and edits the Sqlite3 db to point Django to the correct media path – these images however is not displayed when "debug=False". It works when "debug=True".
When clicking image I get the message:
Not Found
The requested resource was not found on this server.
It’s my first Django project so I’m a little out of my depth and I’m not really sure what to google.
Anyone have any ideas how to make this work or how I could do this another way?
My guess would be that it has something to do with static files?
Project structure:
|mysite
|__warehouse
|__static
|__mysite
|__media
| |__lots of folders
| |__(image)
|__cameras
Apache django.config:
Alias /static /home/usr/mysite/static
<Directory /home/usr/mysite/static>
Require all granted
</Directory>
Alias /media /home/usr/mysite/media
<Directory /home/usr/mysite/media>
Require all granted
</Directory>
<Directory /home/usr/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Static/Media root/url:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = 'static/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = 'media/'
2
Answers
I figured it out.
My main app warehouse have url:
My secondary app have url:
So when I tried to display images it was trying to load from:
Added a "/" before the url in html and now it seems to be working fine.
Did I learn something from this? I'm not sure yet... but for now I'm just gonna enjoy the feeling of success!
Have you tried something like: