D
D
danyarob2021-11-19 17:47:12
Python
danyarob, 2021-11-19 17:47:12

Can I somehow use other folders in flask?

You can somehow use /css/main.css to connect css,
for js: /js/main.js,
not /static/....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RuslanUC, 2021-11-19
@danyarob

You can change /static/ to something else:

app = Flask(__name__, static_url_path='/js_and_css')

You can also do as you wish, but then you will need to add the following code:
from flask import send_from_directory

@app.route('/css/<filename>')
def css_folder(filename):  
    return send_from_directory('css', filename)

@app.route('/js/<filename>')
def js_folder(filename):  
    return send_from_directory('js', filename)

Then js and css will be taken from /js/ and /css/ folders.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question