Как я могу использовать несколько функций на одной странице без изменения URL с помощью Django?

Я пытаюсь использовать Django для создания моего приложения yt-dlp, я хочу создать одну страницу со списком переключения или несколькими кнопками, когда я использую первое действие на списке переключения или кнопке, yt-dlp будет загружать видео файл или лучшее качество видео, и когда я использую второе действие, yt-dlp будет загружать аудио файл, я пробовал это

#views.py
from django.shortcuts import render, redirect
from yt_dlp import YoutubeDL

def hq(request):
    
    if request.method == 'POST':
        URLS = request.POST['HQ'] # to input a url by the user
        opt = {
            'format' : 'bestvideo/best'
        }
        with YoutubeDL(opt) as ydl: # with used to put ydl_opts and apply changes
            ydl.download(URLS) # to start downloading 

        # print('Successfully downloaded')
    return render(request, 'video.html')
# Create your views here.

def ad(request):
    
    if request.method == 'POST':
        URLS = request.POST['audio'] # to input a url by the user
        opt = {
            'format': 'bestaudio/best',
        }
        with YoutubeDL(opt) as ydl: # with used to put ydl_opts and apply changes
            ydl.download(URLS) # to start downloading 

        # print('Successfully downloaded')
    return render(request, 'audio.html')
# Create your views here.

def list(request):
    return render(request, 'list.html')

#list.html 
{% extends 'base.html' %}

{% block title %} 

list

{% endblock title %}



{% block body %}

<ul class="nav justify-content-center">
    <li class="nav-item">
      <a class="nav-link active" aria-current="page" href="http://127.0.0.1:8000/audio"> audio </a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="http://127.0.0.1:8000/ydl">video</a>
    </li>
</ul>

{% endblock body %}

#audio.html 
{% extends 'base.html' %}

{% block title %}
audio only 
{% endblock title %}


{% block body%}

<h1 class="display-1"> audio only </h1>

<form method="post">
    {% csrf_token %}

<div class="input-group mb-3">
    <button class="btn btn-outline-secondary" type="submit" id="button-addon1">Button</button>
    <input type="text" name="audio" class="form-control" placeholder="audio only" aria-label="Example text with button addon" aria-describedby="button-addon1">
</div>

</form>
{% endblock body %}

#video.html
{% extends 'base.html' %}

{% block title %} 

best hq only 

{% endblock title %}


{% block body %}

<h1 class="display-1"> best hq only </h1>

<br>

<form action="" method="post">
    {% csrf_token %}

<div class="input-group mb-3">
    <button class="btn btn-outline-secondary" type="submit" id="button-addon1">Button</button>
    <input type="text" name="HQ" class="form-control" placeholder="BEST HQ" aria-label="Example text with button addon" aria-describedby="button-addon1">
    </div>
</form>

{% endblock body %}

Итак, как я могу использовать функции на одной странице?

Вернуться на верх