Added a website with more features and design and improvements
This commit is contained in:
parent
7b3dc06ad0
commit
8ee3df332c
@ -0,0 +1,58 @@
|
||||
from flask import Flask, render_template, request
|
||||
import requests
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
"""
|
||||
Delete previous code:
|
||||
@app.route('/')
|
||||
def home():
|
||||
return render_template("index.html")
|
||||
@app.route("/login", methods=["POST"])
|
||||
def receive_data():
|
||||
name = request.form["username"]
|
||||
password = request.form["password"]
|
||||
return f"<h1>Name: {name}, Password: {password}</h1>"
|
||||
"""
|
||||
|
||||
# SOLUTION to Challenge:
|
||||
@app.route("/form-entry", methods=["POST"])
|
||||
def receive_data():
|
||||
data = request.form
|
||||
print(data["name"])
|
||||
print(data["email"])
|
||||
print(data["phone"])
|
||||
print(data["message"])
|
||||
return "<h1>Successfully sent your message</h1>"
|
||||
|
||||
|
||||
# Code from Day 59 below:
|
||||
# USE YOUR OWN npoint LINK! ADD AN IMAGE URL FOR YOUR POST. 👇
|
||||
posts = requests.get("https://api.npoint.io/c790b4d5cab58020d391").json()
|
||||
|
||||
@app.route('/')
|
||||
def get_all_posts():
|
||||
return render_template("index.html", all_posts=posts)
|
||||
|
||||
|
||||
@app.route("/about")
|
||||
def about():
|
||||
return render_template("about.html")
|
||||
|
||||
|
||||
@app.route("/contact")
|
||||
def contact():
|
||||
return render_template("contact.html")
|
||||
|
||||
|
||||
@app.route("/post/<int:index>")
|
||||
def show_post(index):
|
||||
requested_post = None
|
||||
for blog_post in posts:
|
||||
if blog_post["id"] == index:
|
||||
requested_post = blog_post
|
||||
return render_template("post.html", post=requested_post)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
@ -0,0 +1,2 @@
|
||||
Flask==2.3.2
|
||||
Requests==2.31.0
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 498 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 118 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 449 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 461 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 112 KiB |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,29 @@
|
||||
/*!
|
||||
* Start Bootstrap - Clean Blog v6.0.9 (https://startbootstrap.com/theme/clean-blog)
|
||||
* Copyright 2013-2023 Start Bootstrap
|
||||
* Licensed under MIT (https://github.com/StartBootstrap/startbootstrap-clean-blog/blob/master/LICENSE)
|
||||
*/
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
let scrollPos = 0;
|
||||
const mainNav = document.getElementById('mainNav');
|
||||
const headerHeight = mainNav.clientHeight;
|
||||
window.addEventListener('scroll', function() {
|
||||
const currentTop = document.body.getBoundingClientRect().top * -1;
|
||||
if ( currentTop < scrollPos) {
|
||||
// Scrolling Up
|
||||
if (currentTop > 0 && mainNav.classList.contains('is-fixed')) {
|
||||
mainNav.classList.add('is-visible');
|
||||
} else {
|
||||
console.log(123);
|
||||
mainNav.classList.remove('is-visible', 'is-fixed');
|
||||
}
|
||||
} else {
|
||||
// Scrolling Down
|
||||
mainNav.classList.remove(['is-visible']);
|
||||
if (currentTop > headerHeight && !mainNav.classList.contains('is-fixed')) {
|
||||
mainNav.classList.add('is-fixed');
|
||||
}
|
||||
}
|
||||
scrollPos = currentTop;
|
||||
});
|
||||
})
|
||||
@ -0,0 +1,47 @@
|
||||
{% include "header.html" %}
|
||||
|
||||
<!-- Page Header-->
|
||||
<header
|
||||
class="masthead"
|
||||
style="background-image: url('../static/assets/img/about-bg.jpg')"
|
||||
>
|
||||
<div class="container position-relative px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<div class="page-heading">
|
||||
<h1>About Me</h1>
|
||||
<span class="subheading">This is what I do.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<!-- Main Content-->
|
||||
<main class="mb-4">
|
||||
<div class="container px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Saepe
|
||||
nostrum ullam eveniet pariatur voluptates odit, fuga atque ea nobis
|
||||
sit soluta odio, adipisci quas excepturi maxime quae totam ducimus
|
||||
consectetur?
|
||||
</p>
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eius
|
||||
praesentium recusandae illo eaque architecto error, repellendus iusto
|
||||
reprehenderit, doloribus, minus sunt. Numquam at quae voluptatum in
|
||||
officia voluptas voluptatibus, minus!
|
||||
</p>
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut
|
||||
consequuntur magnam, excepturi aliquid ex itaque esse est vero natus
|
||||
quae optio aperiam soluta voluptatibus corporis atque iste neque sit
|
||||
tempora!
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{% include "footer.html" %}
|
||||
@ -0,0 +1,97 @@
|
||||
{% include "header.html" %}
|
||||
|
||||
<!-- Page Header-->
|
||||
<header
|
||||
class="masthead"
|
||||
style="background-image: url('../static/assets/img/contact-bg.jpg')"
|
||||
>
|
||||
<div class="container position-relative px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<div class="page-heading">
|
||||
<h1>Contact Me</h1>
|
||||
<span class="subheading">Have questions? I have answers.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<!-- Main Content-->
|
||||
<main class="mb-4">
|
||||
<div class="container px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<p>
|
||||
Want to get in touch? Fill out the form below to send me a message and
|
||||
I will get back to you as soon as possible!
|
||||
</p>
|
||||
<div class="my-5">
|
||||
<!-- * * * * * * * * * * * * * * *-->
|
||||
<!-- * * Simplified SB Contact Form for the Tutorial* *-->
|
||||
<!-- TODO: add an action and a method to link this form to your main.py -->
|
||||
<form
|
||||
id="contactForm"
|
||||
name="sentMessage"
|
||||
action="{{ url_for('receive_data') }}"
|
||||
method="post"
|
||||
>
|
||||
<div class="form-floating">
|
||||
<input
|
||||
class="form-control"
|
||||
id="name"
|
||||
name="name"
|
||||
type="text"
|
||||
placeholder="Enter your name..."
|
||||
required
|
||||
/>
|
||||
<label for="name">Name</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input
|
||||
class="form-control"
|
||||
id="email"
|
||||
name="email"
|
||||
type="email"
|
||||
placeholder="Enter your email..."
|
||||
required
|
||||
/>
|
||||
<label for="email">Email address</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input
|
||||
class="form-control"
|
||||
id="phone"
|
||||
name="phone"
|
||||
type="tel"
|
||||
placeholder="Enter your phone number..."
|
||||
required
|
||||
/>
|
||||
<label for="phone">Phone Number</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<textarea
|
||||
class="form-control"
|
||||
id="message"
|
||||
name="message"
|
||||
placeholder="Enter your message here..."
|
||||
required
|
||||
style="height: 12rem"
|
||||
></textarea>
|
||||
<label for="message">Message</label>
|
||||
</div>
|
||||
<br />
|
||||
<button
|
||||
class="btn btn-primary text-uppercase"
|
||||
id="submitButton"
|
||||
type="submit"
|
||||
>
|
||||
Send
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{% include "footer.html" %}
|
||||
@ -0,0 +1,42 @@
|
||||
<!-- Footer-->
|
||||
<footer class="border-top">
|
||||
<div class="container px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<ul class="list-inline text-center">
|
||||
<li class="list-inline-item">
|
||||
<a href="#!">
|
||||
<span class="fa-stack fa-lg">
|
||||
<i class="fas fa-circle fa-stack-2x"></i>
|
||||
<i class="fab fa-twitter fa-stack-1x fa-inverse"></i>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="list-inline-item">
|
||||
<a href="#!">
|
||||
<span class="fa-stack fa-lg">
|
||||
<i class="fas fa-circle fa-stack-2x"></i>
|
||||
<i class="fab fa-facebook-f fa-stack-1x fa-inverse"></i>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="list-inline-item">
|
||||
<a href="#!">
|
||||
<span class="fa-stack fa-lg">
|
||||
<i class="fas fa-circle fa-stack-2x"></i>
|
||||
<i class="fab fa-github fa-stack-1x fa-inverse"></i>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="small text-center text-muted fst-italic">Copyright © Your Website 2023</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
<!-- Bootstrap core JS-->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<!-- Core theme JS-->
|
||||
<script src="{{ url_for('static', filename='js/scripts.js') }}"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
|
||||
<meta name="description" content="" />
|
||||
<meta name="author" content="" />
|
||||
<title>Clean Blog - Start Bootstrap Theme</title>
|
||||
<link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='assets/favicon.ico') }}" />
|
||||
<!-- Font Awesome icons (free version)-->
|
||||
<script src="https://use.fontawesome.com/releases/v6.3.0/js/all.js" crossorigin="anonymous"></script>
|
||||
<!-- Google fonts-->
|
||||
<link href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css" />
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css" />
|
||||
<!-- Core theme CSS (includes Bootstrap)-->
|
||||
<link href="{{ url_for('static', filename='css/styles.css') }}" rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<!-- Navigation-->
|
||||
<nav class="navbar navbar-expand-lg navbar-light" id="mainNav">
|
||||
<div class="container px-4 px-lg-5">
|
||||
<a class="navbar-brand" href="index.html">Start Bootstrap</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
|
||||
Menu
|
||||
<i class="fas fa-bars"></i>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarResponsive">
|
||||
<ul class="navbar-nav ms-auto py-4 py-lg-0">
|
||||
<li class="nav-item"><a class="nav-link px-lg-3 py-3 py-lg-4" href="{{ url_for('get_all_posts') }}">Home</a></li>
|
||||
<li class="nav-item"><a class="nav-link px-lg-3 py-3 py-lg-4" href="{{ url_for('about') }}">About</a></li>
|
||||
<!-- <li class="nav-item"><a class="nav-link px-lg-3 py-3 py-lg-4" href="post.html">Sample Post</a></li> -->
|
||||
<li class="nav-item"><a class="nav-link px-lg-3 py-3 py-lg-4" href="{{ url_for('contact') }}">Contact</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@ -0,0 +1,45 @@
|
||||
{% include "header.html" %}
|
||||
|
||||
<!-- Page Header-->
|
||||
<!-- <header class="masthead" style="background-image: url({{ url_for('static', filename='assets/img/home-bg.jpg') }})">-->
|
||||
<header class="masthead" style="background-image: url('https://images.unsplash.com/photo-1470092306007-055b6797ca72?ixlib=rb-1.2.1&auto=format&fit=crop&w=668&q=80')">
|
||||
<div class="container position-relative px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<div class="site-heading">
|
||||
<h1>Clean Blog</h1>
|
||||
<span class="subheading">A Blog Theme by Start Bootstrap</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<!-- Main Content-->
|
||||
<div class="container px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
|
||||
<!-- Post preview-->
|
||||
{% for post in all_posts %}
|
||||
<div class="post-preview">
|
||||
<a href="{{ url_for('show_post', index=post.id) }}">
|
||||
<h2 class="post-title">{{ post.title }}</h2>
|
||||
<h3 class="post-subtitle">{{ post.subtitle }}</h3>
|
||||
</a>
|
||||
<p class="post-meta">
|
||||
Posted by
|
||||
<a href="#!">{{ post.author }}</a>
|
||||
on {{ post.date }}
|
||||
</p>
|
||||
</div>
|
||||
<!-- Divider-->
|
||||
<hr class="my-4" />
|
||||
{% endfor %}
|
||||
|
||||
<!-- Pager-->
|
||||
<div class="d-flex justify-content-end mb-4"><a class="btn btn-primary text-uppercase" href="#!">Older Posts →</a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% include "footer.html" %}
|
||||
@ -0,0 +1,32 @@
|
||||
{% include "header.html" %}
|
||||
|
||||
<!-- Page Header-->
|
||||
<header class="masthead" style="background-image: url('{{ post.image_url }}')">
|
||||
<div class="container position-relative px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<div class="post-heading">
|
||||
<h1>{{ post.title }}</h1>
|
||||
<h2 class="subheading">{{ post.subtitle }}</h2>
|
||||
<span class="meta">Posted by
|
||||
<a href="#">{{ post.author }}</a>
|
||||
on {{ post.date }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- Post Content-->
|
||||
<article class="mb-4">
|
||||
<div class="container px-4 px-lg-5">
|
||||
<div class="row gx-4 gx-lg-5 justify-content-center">
|
||||
<div class="col-md-10 col-lg-8 col-xl-7">
|
||||
<p>{{ post.body }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
{% include "footer.html" %}
|
||||
Loading…
Reference in New Issue
Block a user