Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

395
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda