In my Flask App, I'm making a bunch of a hrefs
that will redirect the user to another page that contains an input form. This input-form will be pre-filled via this.innerHTML
It works perfectly on all browsers except for firefox, where I get the ValueError: View function did not return a response
.
{% for x in text %}
<p>{{ x["address"] }} : <strong><a href="">{{ x["car_park_no"] }}</a></strong> </p>
{% endfor %}
This is particularly confusing for me as I've checked everywhere on Google and SO and tried all the possible fixes that could be Firefox related... (window.location)
vs (window.location.href)
vs (window.location.assign)
vs make function return false
I understand that there are questions on SO regarding how this error only occurs when functions do not return a response - However my function here already returns a response. And this error does not occur on Chrome/Internet Explorer/Safari/Edge, only on Firefox.
<script>
// add query strings
window.onload = function() {
var elements = document.getElementsByTagName('a');
for(var i = 0, len = elements.length; i < len; i++) {
elements[i].onclick = function () {
event.preventDefault();
window.location = "/lotfinder?address=" + this.innerHTML;
}, false;
}
}
</script>
Any help would be appreciated, do leave a comment if you require more code snippets.
edit: Code at /lotfinder endpoint
<h1>carpark.py</h1>
<form action = "/carpark" method = "POST">
<p>Carpark No: <input type = "text" id="carpark-input" name = "Carpark" required></p>
<p><input type = "submit" value = "submit"></p>
</form>
</body>
<script>
const carparkInput = document.getElementById("carpark-input");
// use new URLSearchParams API instead of ugly regex querystring parsing
window.onload = function() {
var urlParams = new URLSearchParams(window.location.search);
carparkInput.value = urlParams.get('address');
}
</script>
Above is HTML, below is the Handler
@app.route('/lotfinder',methods = ['POST', 'GET'])
def car1():
if request.method == 'GET':
return render_template("car1.html")