Answers for "how to run my flask, html, js and css files files"

2

flask make static directory

from flask import Flask, send_from_directory

app = Flask(__name__)

@app.route("/static/<path:path>")
def static_dir(path):
    return send_from_directory("static", path)

if __name__ == "__main__":
    app.run()
Posted by: Guest on May-27-2020
2

css and js on flask

<!-- Put in HTML file--> 

<!-- 
JS
parent_dir is reletive to Flask app.py dir
meaning: /main/app.py
		 /main/parent_dir/file.js
-->
<script src="{{url_for('parent_dir', filename='file.js')}}"></script>

<!-- 
CSS
parent_dir is reletive to Flask app.py dir
meaning: /main/app.py
		 /main/parent_dir/file.css
-->
        <link href="{{ url_for("parent_dir",filename="file.css")  }}" rel="stylesheet">
Posted by: Guest on November-04-2020

Python Answers by Framework

Browse Popular Code Answers by Language