I am trying to pass a variable from Flask, to an HTML template, and then use that variable in a separate JavaScript file.
routes.py
fav_photo_index = Photo_Index()
@app.route("/slideshow", methods=["POST", "GET"])
def slideshow():
    cur_image_index = fav_photo_index
    print(cur_image_index.index, image_urls[cur_image_index.index])
    if request.method == "POST":
        update_index(request, cur_image_index)
    favorite = is_favorite(image_urls[cur_image_index.index])
    return render_template('slideshow.html',
                           title="Slideshow",
                           images=image_urls,
                           favorite=favorite,
                           index=cur_image_index.index)
I want to use index variable in a JS file.  I've seen in various places how to use that variable in the HTML template, but not how to pass it to a .js file for use there...
slideshow.js
var slideIndex = "{{index}}";
showDivs(slideIndex);
function plusDivs(n) {
  showDivs(slideIndex += n);
}
function showDivs(n) {
  var i;
  var x = document.getElementsByClassName("slide");
  if (n > x.length) {slideIndex = 1} 
  if (n < 1) {slideIndex = x.length} ;
  for (i = 0; i < x.length; i++) {
    // x[i].style.display = "none";
    x[i].classList.remove('slide-visible'); 
  }
  // x[slideIndex-1].style.display = "block"; 
  x[slideIndex-1].classList.add('slide-visible');
}
As you can hopefully see, I want the index variable to get used in the .js file...How can I do that?
So far I've just tried adding the variable in the head of slideshow.html but it's not working:
Current slideshow.html:
{% extends "layout.html" %}
{% block topscripts %}
    <link rel="stylesheet" type="text/css" href= "{{ url_for('static',filename='styles/slideshow.css') }}">
{% endblock %}
{% block content %}
{% include "/HTML Snippets/favorite_button.html" %}
<div class="slideshow-container">
    {% for image in images %}
        {% if image != "favicon.ico" %}
        <img class="slide" src="{{ url_for('static', filename='images/' + image) }}">
        {% endif %}
    {% endfor %}    
<form action="" method="post">
<input type="hidden" name="prev-next-buttons">
<button class="w3-button w3-display-left" name='prev-photo' onclick="plusDivs(-1)">❮</button>
<button class="w3-button w3-display-right" name='next-photo' onclick="plusDivs(+1)">❯</button>
</div>
</form>
{% endblock %}
{% block endscripts %}
    <script type="text/javascript" src="{{ url_for('static', filename='scripts/slideshow.js') }}"></script>
{% endblock %}
But it doesn't pass that variable to the .js file for use.  The console shows the error:
Uncaught TypeError: Cannot read property 'classList' of undefined
at showDivs (slideshow.js:24)
at slideshow.js:2
FYI here's layout.html:
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href= "{{ url_for('static',filename='styles/layout.css') }}">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        {% block topscripts %}
        {% endblock %}
    </head>
  <body>
    <div class="topnav">
      <a class="active" href="{{url_for('main')}}">Index</a>
      <a class="active" href="{{url_for('favorites')}}">Favorites</a>
      <a class="active" href="{{url_for('slideshow')}}">Slideshow</a>
    </div>
    <div class="container">
        {% block content %}
        {% endblock %}
    </div>
  </body>
  <script type="text/javascript" src="{{ url_for('static', filename='scripts/jscript.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='scripts/jQueryRotate.js') }}"></script>
    {% block endscripts %}
    {% endblock %}
</html>
 
     
     
     
    