-
-
Save angelabauer/df4ab0709c788cfdcf81a00316f4f018 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<link href="https://fonts.googleapis.com/css2?family=Raleway" rel="stylesheet"> | |
<link rel="stylesheet" href="static/css/styles.css"> | |
</head> | |
<body> | |
<div class="wrapper"> | |
<div class="top"> | |
<div class="title"><h1>My Blog</h1></div> | |
</div> | |
{% for post in all_posts: %} | |
<div class="content"> | |
<div class="card "> | |
<h2>{{ post.title }}</h2> | |
<p>{{ post.subtitle }}</p> | |
<a href="{{ url_for('show_post', index=post.id) }}">Read</a> | |
</div> | |
</div> | |
{% endfor %} | |
</div> | |
</body> | |
<footer> | |
<p>Made with ♥️ in London.</p> | |
</footer> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template | |
from post import Post | |
import requests | |
posts = requests.get("https://api.npoint.io/5abcca6f4e39b4955965").json() | |
post_objects = [] | |
for post in posts: | |
post_obj = Post(post["id"], post["title"], post["subtitle"], post["body"]) | |
post_objects.append(post_obj) | |
app = Flask(__name__) | |
@app.route('/') | |
def get_all_posts(): | |
return render_template("index.html", all_posts=post_objects) | |
@app.route("/post/<int:index>") | |
def show_post(index): | |
requested_post = None | |
for blog_post in post_objects: | |
if blog_post.id == index: | |
requested_post = blog_post | |
return render_template("post.html", post=requested_post) | |
if __name__ == "__main__": | |
app.run(debug=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<link href="https://fonts.googleapis.com/css2?family=Raleway" rel="stylesheet"> | |
<link rel="stylesheet" href="static/css/styles.css"> | |
</head> | |
<body> | |
<div class="wrapper"> | |
<div class="top"> | |
<div class="title"><h1>My Blog</h1></div> | |
</div> | |
<div class="content"> | |
<div class="card"> | |
<h1> {{ post.title }}</h1> | |
<h2> {{ post.subtitle }}</h2> | |
<p> {{ post.body }}</p> | |
</div> | |
</div> | |
</div> | |
</body> | |
<footer> | |
<p>Made with ♥️ in London.</p> | |
</footer> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post: | |
def __init__(self, post_id, title, subtitle, body): | |
self.id = post_id | |
self.title = title | |
self.subtitle = subtitle | |
self.body = body |
Alex-V69
commented
Aug 28, 2024
main_d57.py |
---|
d57_index.html |
---|
d57_post.html |
---|
Who are you please?
…On Wed, Aug 28, 2024, 11:37 PM Alex-V69 ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
main_d57.py
from flask import Flask, render_template, abortimport requestsfrom time import sleep
def get_info(url, retries=3, **kwargs):
with requests.Session() as session:
for i in range(retries):
response = session.get(url, **kwargs)
print("Status:", response.status_code)
if response.status_code == 200:
return response.json()
elif i < retries - 1:
sleep(1 * (i + 1))
app = Flask(__name__)data = get_info('https://api.npoint.io/<your_unique_id_here>')
@***@***.***('/blog')def home():
if not data:
abort(500)
context = {
'title': "My blog",
'posts': data
}
return render_template("d57_index.html", **context)
@app.route('/post/<int:id>')def blog_post(id):
if id > len(data) or id == 0:
abort(404)
context = {
'title': "My blog",
'post': data[id-1]
}
return render_template("d57_post.html", **context)
if __name__ == "__main__":
app.run(debug=True)
d57_index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{{ title }}{% endblock title %}</title>
<link href="https://fonts.googleapis.com/css2?family=Raleway" rel="stylesheet">
<link rel="stylesheet" href="../static/css_d57/styles.css">
</head>
<body>
<div class="wrapper">
<div class="top">
<div class="title"><h1>{% block heading %}{{ title }}{% endblock heading %}</h1></div>
</div>
{% block content %}
{% for item in posts %}
<div class="content">
<div class="card">
<h2>{{ item.title }}</h2>
<p class="text">{{ item.subtitle }}</p>
<a href="{{ url_for('blog_post', id=item.id) }}" id="{{ item.id }}">Read</a>
</div>
</div>
{% endfor %}
{% endblock content %}
</div>
</body>
<footer>
<p>Made by 💀 in 🏰</p>
</footer>
</html>
d57_post.html
{% extends "d57_index.html" %}{% block title %}{{ title }} - {{ post.title }}{% endblock title %}{% block heading %}
<a href="{{ url_for('home') }}#{{ post.id }}" id="home">{{ title }}</a> - {{ post.title }}{% endblock heading %}{% block content %}
<div class="content">
<div class="card">
<h2>{{ post.title }}</h2>
<p>{{ post.body }}</p>
</div>
</div>{% endblock content %}
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/angelabauer/df4ab0709c788cfdcf81a00316f4f018#gistcomment-5171058>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQNSFIORIHJUBQDLVLYRO3DZTZGLTBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTANJZHE4TOMJYU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment