How can I get a FileField
link? I tried the url
field, but it gives the file path:
In [7]: myobject.myfilefield.path Out[7]: u'/home/xxxx/media/files/reference/1342188147.zip' In [8]: myobject.myfilefield.url Out[8]: u'/home/xxxx/media/files/reference/1342188147.zip'
I expected to get http://<mydomain>/media/files/reference/1342188147.zip
How can i get this? Do I need to build a string manually?
EDIT
My MEDIA_URL has not been set, but I still cannot get it to work:
settings.py
MEDIA_ROOT = '/home/xxx/media/' MEDIA_URL = 'http://xxx.com/media/'
models.py
class Archive(models.Model):
in the shell
a = Archive() a.file = "/some/path/to/file.txt" a.save()
Then I get for a.path
:
"/some/path/to/file.txt"
and for a.url
:
"http://xxx.com/media/some/path/to/file.txt"
When programmatically, a.file = "/some/path/to/file.txt"
, the file does not load into MEDIA_ROOT
. How to upload a file to the directory specified by upload_to
, i.e. in my case /home/xxx/media/file.txt
?
source share