I'm coding a website with flask. I'm using flask route only to render html files with the function send_from_directory
. The current structure is the followng:
- website
- app.py
- views.py
- static/
- index.html
- login.html
- styles/style.css
- script/
- core.js
I cant load the css and js with hyperef from a HTML file by using a route AND a hyperlink. For exemple : i can either load the full login page (content and layout) by clicking the link i put in my index page OR i can load the full page by directly typing in the URL, depending on how i code my page. Is there a way to be able to load the full page no matter how i access it?
this is how i code it to access it by typing the url :<link rel="stylesheet" href="static/styles/style.css">
and this is how i code it to access it throught an hyperlink :<link rel="stylesheet" href="styles/style.css">
Thanks for you time.
I tried this:
from flask import Blueprint, render_template, send_from_directory
views = Blueprint("views", __name__, static_folder="static", template_folder="static")
@views.route("/")
def home():
return send_from_directory("static", "index.html")
@views.route("/login")
def login():
return send_from_directory("static", "login.html")