Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

403
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda