Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

388
Views
JavaScript redirect with port number with url_for('views.home')

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!