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

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

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 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