Reputation: 41
I have been trying to add CSS to my webpage using flask but it's not happening. If I run my webpage independently, it shows the CSS effects. But when I run the python code it displays plain HTML form.
This is HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-g">
<title>Forms</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
</head>
<body>
<form action="/view" method="POST" enctype="multipart/form-data">
<div>
<p>
<label for="name">Name
<input name="name" type="text" placeholder="Enter Name">
</label>
</p>
</div>
<div>
<p>E-mail
<input name="email" type="email">
</p>
</div>
<div>
<p>Password
<input name="pass" type="password">
</p>
</div>
<div>
<p>
<input name="file" type="file">
</p>
</div>
<div>
<p>
<input type="submit">
</p>
</div>
</form>
</body>
</html>
This is the python code:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return render_template("forms.html")
if __name__ == '__main__':
app.run(host='192.168.1.7', port=int(8000), debug=True)
print("Server Started successfully")
Upvotes: 1
Views: 103
Reputation: 529
There is a slight issue with your code.
Try adding the following as href for stylesheet:
url_for('static', filename='css/style.css')
Argument filename must have the path of file inside static folder.
Upvotes: 2