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

206
Visualizações
Python Flask blueprint without static folder for css and javascript

I have searched similar answer to this and found to no avail.

Using CGI Handler Apache server with an index.cgi

I have to adhere the strict policy on the directory list; they're adamantly refused to have a static folder in the directory for Flask.

I kinda wish Flask add static_js and static_css that would make our life easier.

How do I override the static folder?

It works with a single path for either css or javascript:

# in app.py
app.register_blueprint(index_bp)
app.add_url_rule('/css/<path:filename>', endpoint='css', view_func=app.send_static_file)

app.add_url_rule('/js/<path:filename>', endpoint='js', view_func=app.send_static_file)
# css_dir = /parent_folder/css and read from json load
from config import css_dir

index = Blueprint('index', __name__, template_folder=html_dir, static_folder=css_dir)

# in html file
<link rel='stylesheet' href="{{ url_for('css', filename='bootstrap.min.css') }}">

# note: javascript won't load at all

or

# js_dir = /parent_folder/js and read from json load
from config import js_dir

index = Blueprint('index', __name__, template_folder=html_dir, static_folder=css_dir)

# in the html file
<script type ="text/javascript" src="{{ url_for('js', filename='lib/bootstrap.min.js') }}"></script>

# note: css won't load at all

but does not work:

# multi_dir = /parent_folder and read from json load
from config import multi_dir

index = Blueprint('index', __name__, template_folder=html_dir, static_folder=multi_dir)

# in html file
<link rel='stylesheet' href="{{ url_for('css', filename='bootstrap.min.css') }}">

<script type ="text/javascript" src="{{ url_for('js', filename='lib/bootstrap.min.js') }}"></script>

# note: both won't load at all

I want to include javascript and css folders without a static folder

  1. parent_folder
    • cgi-bin
      • python/perl stuff
    • templates
      • html stuff
    • css
      • css stuff
    • js
      • lib
        • javascript stuff

How do I achieve this?

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

0

I figured it out, it can be achieved by create a two python files and register them in the app.py blueprint.

Since Stack Overflow won't let me post code in here due to error which is in correct format.

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