我想要得到我上传的最后一个文件,它将在模板中播放。但我所做的,我上传的每一个文件,它都可以播放(所以有这么多音频播放器)。我想要的只是显示一个音频播放器与最后的音频我是上传它。我试过了,但对我不起作用。
我的html:
<audio controls="controls">
<source src="/media/mp3/{{last_audio.audio}}" type="audio/mpeg">
</audio>
views.py:
def homepage(request):
form = AudioForm()
last_audio = Audio_store.objects.last()
if request.method == "POST":
form = AudioForm(request.POST, request.FILES)
if form.is_valid():
form.save()
audio = form.cleaned_data.get("audio")
print(audio)
context={'form':form, 'last_audio':audio}
return render(request, 'homepage.html', context)
context={'form':form, 'last_audio':last_audio}
return render(request, "homepage.html", context=context)
这不是错误但是现在音频控件没有出现,但是音频可以被选择最后一个
view
def homepage(request):
form = AudioForm()
last_audio = Audio_store.objects.last()
if request.method == "POST":
form = AudioForm(request.POST, request.FILES)
if form.is_valid():
form.save()
audio = form.cleaned_data.get("audio")
return render(request, home.html, {'last_audio':audio})
context={'form':form, 'last_audio':last_audio}
print(audio)
return render(request, "homepage.html", context=context)
html
<audio controls="controls">
<source src="/media/mp3/{{last_audio.audio}}" type="audio/mpeg">
</audio>