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

198
Visualizações
Flask CSS loading issues with redirect

I want people to be redirected to the route /profil when they join the app if they are not registered. The problem is that either CSS and Javascript won't load on the page (whereas they do when I delete the following code) :

@app.before_request
def before_request_func():
    global ip_addr
    ip_addr=request.environ.get('HTTP_X_FORWARDED_FOR', request.remote_addr)
    if not(ip_addr in [i[2] for i in auth.getUsers()]) and request.path!='/profil':
        return redirect(url_for('profil'))

More, the server shell prints :

127.0.0.1 - - [16/Mar/2022 20:28:23] "GET /profil HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2022 20:28:23] "GET /static/css/style.css HTTP/1.1" 302 -
127.0.0.1 - - [16/Mar/2022 20:28:23] "GET /static/javascript/script.js HTTP/1.1" 302 -
127.0.0.1 - - [16/Mar/2022 20:28:23] "GET /profil HTTP/1.1" 200 -
127.0.0.1 - - [16/Mar/2022 20:28:23] "GET /profil HTTP/1.1" 200 -

Here are my other source codes :

base.html

<!doctype html>
<html lang="fr">
<head>
    <meta charset="utf-8">
    <meta name="viewport" >
    <link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='css/style.css') }}">
    <link rel="icon" type="image/png" href="../static/images/logo.png" />
  <title>{% block title %} {% endblock %}</title>
  </head>
  <body>
      <canvas id="c" class="bg"></canvas>
    <div id="profil">{{username}}</div>
      <div id="content">
            {% block content %} {% endblock %}
      <a href="{{url_for('index')}}">
        </div>
      <div class="prospectus">
        <div class="trademark">
          <p class="trademark_style">DECRYPTO </p>
          <p>©2022 Décrypto</p>
        </div>
      </div>
    </a>
      <script src="../static/javascript/script.js"> </script>
  </body>
</html>

profil.html

{% extends 'base.html' %}
{% block title %}Authentification{% endblock %}
{% block content %}
    <h1>Hello World</h1>
{%endblock%}

If someone has any idea on how to fix it... Thank you

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

After some more reflexions, I figured out the problem which is quite simple yo solve : when the client was requesting CSS, it was redirected to the profile route (making an infinite loop). To fix it, we can simply modify the condition as following :

@app.before_request
def before_request_func():
    global ip_addr
    ip_addr=request.environ.get('HTTP_X_FORWARDED_FOR', request.remote_addr)
    if not(ip_addr in [i[2] for i in auth.getUsers()]) and not(request.path in ['/profil','/static/CSS/style.css','/static/javascript/script.js']):
        return redirect(url_for('profil'))
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