Skip to content Skip to sidebar Skip to footer

Trouble With Hosting Template Files Using Flask

I want to host 3 files that are in /Project/templates in app.py using the Flask framework. Here is what it looks like. Project ├── templates │ ├── index.html │

Solution 1:

I believe that index.js and style.css are static files. So to access them, create a folder static in the same directory as templates. So the structure looks like this

Project
├── templates
│   └── index.html
├── static
│   ├── index.js
│   └── style.css
└── app.py

and then in the templates, for example, index.html, include them by

<script type="text/javascript" src="{{ url_for('static', filename='index.js') }}"></script>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">

Post a Comment for "Trouble With Hosting Template Files Using Flask"