'how to make audio player from local storage with DJANGO FORMS

so i want make audio player, the song it's form my local storage. i was new in django, so i have no idea to make it. i want make it using FORMS not models.

here's my form.py :

from django import forms

class Audio_store(forms.Form):
    password=forms.FileField(widget=forms.FileInput(attrs={'style': 'width: 300px;', 'class': 'form-control', 
    'text-align' : 'center;'}))
    audio=forms.FileField(widget=forms.FileInput(attrs={'style': 'width: 300px;', 'class': 'form-control', 
    'text-align' : 'center;'}))

views.py :

def handle_uploaded_file1(f):
    with open('txt/'+f.name, 'wb+') as destination:
        for chunk in f.chunks():
            destination.write(chunk)

def homepage(request):
    form_class = Audio_store
    form = form_class(request.POST or None)
    if request.method == "POST":
        form = Audio_store(request.POST, request.FILES)
        if form.is_valid():
            handle_uploaded_file1(request.FILES['password'])
            handle_uploaded_file(request.FILES['audio'])
            return render(request, "homepage.html", {'form': form})
    return render(request, "homepage.html", {'form': form})

web

so when i click button play, the music what i uploaded it can be played. you can modification too (not must using button play, using in html it's okay too!). please help me



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source