Flask python simple website

Flask:
Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries.
Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications.
Follow the below steps to create a simple website using Flask
- Create an app.py file and copy-paste the #app.py code there.
- Create two folders named templates and a static folder. Those folders should be in the same directory with your app.py file.
- Create four files inside the templates folder, layout.html, home.html, about.html , and main.css and copy-paste the code of #layout.html, #home.html, #about.html and #main.css in those files, respectively.
- Execute app.py in pycharm
- Visit localhost:5000(http://127.0.0.1:5000/) on your browser to see the website.
6. If you get an error make sure you created the correct directory structure as explained in steps 1 to 3 It should be:
templates/
layout.html
home.html
about.html
main.css
static/
photo.jpg
slides.gif
app.py
Find the below images:



#app.py
from flask import Flask, render_template,url_for
app=Flask(__name__)
@app.route('/')
def home():
app.route('/')
return render_template("home.html")
@app.route('/about/')
def about():
return render_template("about.html")
if __name__=="__main__":
app.run(debug=True)
#layout.html
<!DOCTYPE html>
<html>
<head>
<title>Flask App</title>
<link rel="stylesheet" href="{{url_for('static',filename='main.css')}}">
</head>
<body>
<header>
<div class="container">
<h1 class="logo">Ardit's web app</h1>
<strong><nav>
<ul class="menu">
<li><a href="{{ url_for('home') }}">Home</a></li>
<li><a href="{{ url_for('about') }}">About</a></li>
</ul>
</nav></strong>
</div>
</header>
<div class="container">
{%block content%}
{%endblock%}
</div>
</body>
</html>
#home.html
{%extends "layout.html"%}
{% block content %}
<div class="home">
<h1>My homepage</h1>
<p>GVK CHinmaya Vidyalaya Home page</p>
<img src="{{url_for('static', filename='slides.gif')}}" align="middle" />
<div>
{%endblock%}
#about.html
{%extends "layout.html"%}
{% block content %}
<div class="about">
<h1>My about page</h1>
<body><img src="{{url_for('static', filename='PHOTO.JPG')}}" align="middle" /><P>CHINTHALA VIJAYA KUMAR</P>
<P>PGT Computer Science</P>
</body>
<div>
{%endblock%}
#main.css
body {
margin: 0;
padding: 0;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #060;
}
/*
* Formatting the header area
*/
header {
background-color: #DFB887;
height: 35px;
width: 100%;
opacity: .9;
margin-bottom: 10px;
}
header h1.logo {
margin: 0;
font-size: 1.7em;
color: #fff;
text-transform: uppercase;
float: left;
}
header h1.logo:hover {
color: #fff;
text-decoration: none;
}
/*
* Center the body content
*/
.container {
width: 1200px;
margin: 0 auto;
}
div.home {
padding: 10px 0 30px 0;
background-color: #E6E6FA;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
div.about {
padding: 10px 0 30px 0;
background-color: #E6E6FA;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
h2 {
font-size: 3em;
margin-top: 40px;
text-align: center;
letter-spacing: -2px;
}
h3 {
font-size: 1.7em;
font-weight: 100;
margin-top: 30px;
text-align: center;
letter-spacing: -1px;
color: #999;
}
.menu {
float: right;
margin-top: 8px;
}
.menu li {
display: inline;
}
.menu li + li {
margin-left: 35px;
}
.menu li a {
color: #444;
text-decoration: none;
}
Output:


