Issue
could you, please, help me?
I'm trying to add a css file on a website.
This website was made by flask, html, css and uploaded on HEROKU. When I was just in HTML, the homepage was working normally, now that I linked the css, I got this error:
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
When I move to other page without css, It works, but I don't know what's wrong.
HTML:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='css/reset.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/homepage.css') }}">
<title>HomeD3v</title>
</head>
<body>
<h1>nogD3V</h1>
<h2>BUILDING</h2>
</body>
</html>
PYTHON:
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def homepage():
return render_template("homepage.html")
@app.route("/contatos")
def contatos():
return render_template("contatos.html")
@app.route("/usuarios/<nome_usuario>")
def usuarios(nome_usuario):
return render_template("usuarios.html", nome_usuario=nome_usuario)
if __name__ == "__main__":
app.run(debug=True)
Solution
Well in your case static directory should be in root of your project not inside the template directory, so it should be something like this
/
static/
└── css/
└──style.css
templates/
└── base.html
main.py
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/styles.css')}}">
In this link you can see flask project layout
https://flask.palletsprojects.com/en/2.1.x/tutorial/layout/
Answered By - Mohammad Reza Aram
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.