my website have form using models to upload audio file. when it uploaded, the file cannot be played but at my terminal it’s already detected the file name. but when i open new page, the audio can be play without i need to upload again. anyone know what’s wrong?
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.all().last()
if request.method == "POST":
form = AudioForm(request.POST, request.FILES)
if form.is_valid():
audio = form.cleaned_data.get("audio")
print(audio)
context={'form':form, 'last_audio':audio}
print(context)
form.save()
return render(request, "homepage.html", context=context)
context={'form':form, 'last_audio':last_audio}
return render(request, "homepage.html", context=context)
models.py:
from django.db import models
from django.core.files.storage import FileSystemStorage
fs = FileSystemStorage(location='media/mp3')
fss = FileSystemStorage(location='media/txt')
class Audio_store(models.Model):
password=models.FileField(storage=fss, null=True)
audio=models.FileField(storage=fs, null=True)