As the title states, I am lost here because I can upload files to MEDIA_ROOT via the site, but when I attempt to serve them I get a 404 error. The most annoying part is that this worked for ages, now something changed and it's broken.
UPDATE: I've narrowed the problem down.
If I change:
MEDIA_URL = '/media/'
Django serves the file at http://192.168.xxx.xxx/media/media/file.txt
If I change:
MEDIA_URL = '/kittens/'
Django serves the file at http://192.168.xxx.xxx/kittens/file.txt
runserver output:
urls.py MEDIA_URL: /media/
urls.py MEDIA_ROOT:
Settings.py MEDIA_ROOT: /home/user/kittens/
What in the world is going on? Why the "nested" media url path? django.conf.settings.MEDIA_ROOT is blank while mysite.settings.MEDIA_ROOT is not?
urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = patterns('',
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
print 'urls.py MEDIA_URL: %s' % (settings.MEDIA_URL)
print 'urls.py MEDIA_ROOT: %s' % (settings.MEDIA_ROOT)
settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = '/home/user/kittens/'
print 'Settings.py MEDIA_ROOT: %s' % (MEDIA_ROOT)
On the disk
drwxr-xr-x 0 user user 0 Mar 11 11:00 kittens/
-rwxr-xr-x 0 user user 22561 Oct 5 19:17 kittens/file.txt*
In the browser
Page not found (404)
Request Method: GET
Request URL: http://192.168.../media/file.txt
"file.txt" does not exist
python manage.py runserver
[11/Mar/2014 15:00:43] "GET /media/file.txt HTTP/1.1" 404 1629
python manage.py shell
IPython 1.1.0 -- An enhanced Interactive Python.
In [1]: from django.conf import settings
In [2]: settings.MEDIA_ROOT
Out[2]: 'kittens/'
In [3]: settings.MEDIA_URL
Out[3]: '/media/'
In [8]: os.path.join(settings.MEDIA_ROOT, 'file.txt')
Out[8]: 'kittens/file.txt'
In [9]: os.path.exists(os.path.join(settings.MEDIA_ROOT, 'file.txt'))
Out[9]: True
rwand it still fails to serve the file. - JamesMEDIA_ROOTis expected to be absolute - lanzzMEDIA_ROOTis absolute on my box. I'll update the question to reflect that. - James