Copy password to clipboard in Django app

Just finished the Password Generator, and was wondering how you would copy the password to the clipboard like you see a lot of sites do with a small copy button?

think the easiest solution is to use jQuery. really simple solution. all we need is to to add some scripts and and a few changes in html template password.html:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
 
<!-- load jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
 
<div class="container text-center">
  <h1>Your password is:</h1>
  <h2 id="password_to_copy" class="alert alert-success">{‌{ password }}</h2>
  <a href="{% url 'home' %}" class="btn btn-info">Home</a>
  <button id="copyButton" onclick="copyToClipboard('#password_to_copy')" class="btn btn-info">Copy password to clipboard</button>
</div>
    <script>
        function copyToClipboard (element) {
            // create input to handle password copy. we are going to
            // use jQuery select() which trigger selection of text in input
            let $temp = $("<input>");
 
            // append our temporary input to the document
            $("body").append($temp);
 
            // set new value for temp input (we get value from <h2> tag with id password_to_copy)
            // and select it
            $temp.val($(element).text()).select();
 
            try {
              // copy to clipboard selected text and display success msg
              document.execCommand("copy");
              alert("Password: " + $(element).text() + " copied to clipboard");
            } catch (err) {
              // display error msg
              alert("Oops, unable to copy!!! Error: " + err);
            }
            // remove temporary input
            $temp.remove();
        }
    </script>