Skip to content

Commit

Permalink
simple blog using flask & jinja
Browse files Browse the repository at this point in the history
  • Loading branch information
Alter-Sitanshu committed Jun 14, 2024
1 parent 803c171 commit 7fa0e1a
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
20 changes: 20 additions & 0 deletions blogs/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from flask import Flask, render_template
import requests
app = Flask(__name__)

@app.route('/')
def home_page():
response = requests.get("https://api.npoint.io/948a893b298bc81eedf9")
data = response.json()
return render_template("index.html", data=data)


@app.route('/blogs/<id>')
def get_post(id):
response = requests.get("https://api.npoint.io/948a893b298bc81eedf9")
data = response.json()
return render_template("blog.html", data=data, id=int(id))


if __name__ == "__main__":
app.run(debug=True)
63 changes: 63 additions & 0 deletions blogs/static/styling.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
body{
padding: 0;
margin: 0;
}
.head-style{
height: 20vh;
background-color: rgb(125, 255, 255);
z-index: 1;
}
.post{
min-width: 25vw;
max-width: 30vw;
min-height: 30vh;
margin: 2vh auto;
padding: 2vh 1vw;
background-color: rgb(234, 234, 233);
display: flex;
flex-direction: column;
align-items: start;
justify-content: center;
}
.post h2{
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
font-size: 4vh;
color: chartreuse;
margin: 1vh 0;
}
.post h4{
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
font-size: 2vh;
color: rgb(255, 0, 0);
margin: 1vh 0;
}
.post a{
text-decoration: none;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
color: coral;
}
.post p{
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
font-size: 4vh;
}
.all_posts{
z-index: 10;
position: absolute;
top: 8%;
left: 35%;
display: flex;
flex-direction: column;
justify-content: center;
max-width: 70%;
margin: 0 auto;
}
.all_posts h3{
min-width: 25vw;
margin: 2vh auto;
display:block;
}
.all_posts h3{
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
font-size: 3vh;
color: rgb(83, 82, 82);
}
20 changes: 20 additions & 0 deletions blogs/templates/blog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blogs</title>
<link rel="stylesheet" href="../static/styling.css">
</head>
<body>
<div class="head-style"></div>
<div class="all_posts">
<h3>Blogs</h3>
<div class="post">
<h2>{{ data[id-1]["heading"] }}</h2>
<h4>{{ data[id-1]["author"] }}</h4>
<p>{{ data[id-1]["text"] }}</p>
</div>
</div>
</body>
</html>
23 changes: 23 additions & 0 deletions blogs/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../static/styling.css">
<title>Blog Post</title>
</head>
<body>
<div class="head-style"></div>

<div class="all_posts">
<h3>Blogs</h3>
{% for blog in data: %}
<div class="post">
<h2>{{ blog["heading"] }}</h2>
<h4>{{ blog["author"] }}</h4>
<a href="{{ url_for('get_post', id=blog['id']) }}" id="{{ blog['id'] }}">Go to Post</a>
</div>
{% endfor %}
</div>
</body>
</html>

0 comments on commit 7fa0e1a

Please sign in to comment.