Django FileField url not relative
django, django-models, file
Solution
I just did a sample FileField in one of my projects and it seemed to work as you are expecting. Here are a couple things to try.
Try making your settings like the following. I know they say it is bad to not end your MEDIA_URL with a / but this is how I do it and I like it better. You just have to remember whenever you use MEDIA_URL in a template to follow it with a slash: href="{{ MEDIA_URL }}/path/to/file"
MEDIA_ROOT = '/home/httpd/foo/media'
MEDIA_URL = '/media'
If that doesn't help anything, create a new simplified model with a FileField nothing customized and see if you are still getting the same problem.
Problem
I have something like: ``` MEDIA_ROOT = '/home/httpd/foo/media/' MEDIA_URL = 'http://www.example.org/media/' ``` (...) ``` file = models.FileField(upload_to='test') ``` When I create an object with that field in the admin page Django stores in the DB the full file path, like: "/home/httpd/foo/media/test/myfile.pdf". This is contrary to what says in the docs. All that will be stored in your database is a path to the file (relative to MEDIA_ROOT). When I use the file.url in a template I get something like: http://www.example.org/home/httpd/foo/media/test/myfile.pdf instead of what I would like: http://www.example.org/media/test/myfile.pdf What am I doing wrong?