#22717: FileField.url returns a wrong URL
--------------------------------------+-----------------------------------
     Reporter:  david.fischer.ch@…    |      Owner:  nobody
         Type:  Bug                   |     Status:  new
    Component:  File uploads/storage  |    Version:  master
     Severity:  Normal                |   Keywords:  storage,filefield,url
 Triage Stage:  Unreviewed            |  Has patch:  0
Easy pickings:  0                     |      UI/UX:  0
--------------------------------------+-----------------------------------
 models.py:
 {{{
 ...
 class Media(models.Model):
     ....
     file = models.FileField(upload_to=storages.upload_to,
 storage=storages.media_storage)
     ...
 }}}

 storages.py:
 {{{
 ...
 def upload_to(instance, filename):
     return '%s/%s' % (instance.pk, filename)

 media_storage = FileSystemStorage(location='/test/media',
 base_url='/test/media')
 }}}

 Django shell:
 {{{
 ...
 >>> m = Media.objects.get(pk=27)
 >>> m.file.storage.base_url
 '/test/media'
 >>> m.file.name
 'salut.txt'
 >>> m.file.url
 '/test/salut.txt'
 }}}

 Expected -> '/test/media/salut.txt'

 Investigating:
 {{{
 >>> from django.utils.six.moves.urllib.parse import urljoin
 >>> urljoin('/test/media', 'salut.txt')
 '/test/salut.txt'
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22717>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.956e843c13d91b4d677873ea4ebe6b4c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to