Here is my entire 404.html page:
{% extends 'base.html' %}
{% block title %}Page Not Found{% endblock title %}
{% block head %}
<script>
var seconds =7;
// countdown timer.
var url="{{url_for('views.home')}}";
// variable for index.html url - NEEDS PORT NUMBER
function redirect(){
if (seconds <=0){
// redirect to new url after counter down.
window.location = url;
} else {
seconds--;
document.getElementById("pageInfo").innerHTML="Redirecting to Home Page after "
+seconds+" seconds."
setTimeout("redirect()", 1000)
}
}
</script>
{% endblock head %}
{% block content %}
<header><h1>Sorry, the Page was not Found</h1></header>
<h1>Oops! Looks like the page doesn't exist anymore</h1>
<a href="{{ url_for('views.home') }}"><p>Click Here</a>To go to the Home Page</p> Needs port Number for link
<!-- IE needs 512+ bytes: https://docs.microsoft.com/archive/blogs/ieinternals/friendly-http-error-pages -->
{% endblock content %}
{% block body %}
<body onload="redirect()">
<p id="pageInfo"></p>
{% endblock body %}
The problem occurs when the web server is running on port 5000. The redirect uses to port 80. I do not know how to use javascript to redirect to specific port number. Everything else seems to work fine. I need the port number to be used dynamically; the port number may change so I do not want to hard code the port number to the url variable. If there is something else I am missing please don't hesitate to make an comment or solution.
Its possible to build up the url with some js
window.location.origin
Will give you host+port something like http://localhost:3000 or whatever port/host you are running on.
So you can prepend that to your {{url_for('views.home')}} to get a correct url.
Im not sure what the value of your url="{{url_for('views.home')}}"; is so you may need to add an extra / in to make it work.