无法解析 django 模板中的剩余部分

Not able to parse the remainder in django template

<html>
<head>
    <title>{{ songname }}</title>
    <meta charset="UTF-8">
    {% load static %}
</head>
<body>
    <center><h1>MUOSIC</h1></center>
    <hr>
    <audio controls>
    <source src="{% static {{ songname }} %}" type="audio/mpeg">
    </audio>
    <hr>
</body>

这里的歌曲名是我想要的歌曲的名字play.All静态文件在静态directory.From视图函数上面的模板是使用render_to_responsefunction.So 谁能解释一下这个问题的原因。

你不能那样嵌套模板变量。假设您的 songname 是文件的实际名称并且文件位于 STATIC_ROOT 的根目录中,您只需执行以下操作:

{% static songname %}