play <audio></audio> file in django template

对着背影说爱祢 提交于 2019-12-02 11:11:06
Kamal Singh

You should add MEDIA_ROOT and MEDIA_URL configuration. It will be easy to handle things. Here is the solution to your problem.

In settings.py:

MEDIA_ROOT=os.path.join(BASE_DIR,"songdir")
MEDIA_URL='/media/'

Also in settings.py add 'django.template.context_processors.media', in the TEMPLATES option's context_processors.

In project/urls.py:

from django.conf import settings
from django.conf.urls.static import static
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Then you can simply use:

{{link.url}} 

instead of hardcoding it in your template file.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!