I have a situation where, replacing a url string "/CreditHistory/10216" with a jinja2 variable {{creditNumbers|safe}}, messes up the loading of javascript files. More specifically, this works;
{% block Scripter %}
<script type="text/javascript" src="./static/assets/js/crossfilter/crossfilter.js"></script>
<script type="text/javascript" src="./static/assets/js/d3/d3.js" charset="utf-8"></script>
<script type="text/javascript" src="./static/assets/js/dc.js/dc.js"></script>
<script type="text/javascript" src="./static/assets/js/queue/queue.js"></script>
<script src='./static/assets/js/graphsFordringer.js' type='text/javascript' charset="utf-8"></script>
<script type="text/javascript">
queue().defer(d3.json, "/CreditHistory/10216").await(makeGraphs);
</script>
{% endblock %}
But, this does not;
{% block Scripter %}
<script type="text/javascript" src="./static/assets/js/crossfilter/crossfilter.js"></script>
<script type="text/javascript" src="./static/assets/js/d3/d3.js" charset="utf-8"></script>
<script type="text/javascript" src="./static/assets/js/dc.js/dc.js"></script>
<script type="text/javascript" src="./static/assets/js/queue/queue.js"></script>
<script src='./static/assets/js/graphsFordringer.js' type='text/javascript' charset="utf-8"></script>
<script type="text/javascript">
queue().defer(d3.json, "{{creditNumbers|safe}}").await(makeGraphs);
</script>
{% endblock %}
The errors that gets thrown in the web-browser implies that none of the javascript files get loaded. One of them is for example that queue is not a defined function.
What is also apparent is that the "{{creditNumbers|safe}}" variable does load to "/CreditHistory/10216". So, in short the variable loading seems to break the javascript loading. Not that I have found reference to similar issues in the documentation, so that probably is not what is happening.
EDIT:
It now seems that I have misunderstood the entire situation. It looks like it is the way that the jinja2 template variable is declared in the app.py file that is the root cause.
The @app.routecode that is failing is;
@app.route('/KundeFordringer/<int:KundeNr>')
def fordringer(KundeNr):
jsonSti = "/CreditHistory/"+str(KundeNr)
return render_template("fordringer.html", creditNumbers=jsonSti)
However, if I change the code to the following, it works fine;
@app.route('/KundeFordringer')
def fordringer():
return render_template("fordringer.html", creditNumbers="/CreditHistory/10216")
As mentioned previously, viewing the source code from the web browser, one could see that the "/CreditHistory/10216"was loaded when using the first @app.route declaration. But apparently something is, never the less, off with that way of doing it.
Any help would be greatly appreciated
app.pydeclarations, see EDIT in question.<script>from the chrome dev tools ?./instead of just/. I would definitely like to thank you by checking an answer as accepted. You cannot believe how much time I have used with this problem...