i want to get the last file i was upload and it will be played in templates. but what i make it, every file i was upload, it can be played (so there’s so many audio player). what i want is just show 1 audio player with the last audio i was upload it. i was trying with this but it's not work on me.
here's my 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)
it's not error again but now the audio controls not appear, but the audio can be selected the last