[Fixed]-Downloadable file link in django tables

1๐Ÿ‘

โœ…

I think you should get the value of MEDIA_URL instead of MEDIA_ROOT:

def render_download(self):        
    url = static('cloud-download.png')
    href = settings.MEDIA_URL + "/mask.nii.gz"        
    return mark_safe('<a href="' + href + '"><img src="' + url + '"></a>')

You might need to add the following to your main urls.py so your media files can be served by the development web server.

# urls.py

...
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
    # ...your routes...
] 

urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
๐Ÿ‘คflowfree

Leave a comment