patx/micropie
updated website to be more modern
Commit 96f9f7e · patx · 01/23/2025 at 4:53PM
Comments
No comments yet.
Diff
diff --git a/docs/index.html b/docs/index.html
deleted file mode 100644
index a113f46..0000000
--- a/docs/index.html
+++ /dev/null
@@ -1,75 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link rel="shortcut icon" href="https://cherrypy.dev/images/favicon.gif" type="image/x-icon">
- <title>MicroPie - An actual micro web framework</title>
- <style>
- .logo {
- width: 800px;
- margin: 40px auto;
- }
- .body {
- font-family: "Helvetica", sans-serif;
- width: 540px;
- margin: 40px auto;
- }
- img.c1 {
- position: absolute;
- top: 0;
- right: 0;
- border: 0;
- }
- span.c2 {
- color: #8F5902;
- }
- span.c9 {
- color: #B22222;
- }
- a {
- color: #B22222;
- border-bottom: 1px dotted #8F5902;
- text-decoration: none;
- }
- a:hover {
- color: #B22222;
- border-bottom: 1px solid #8F5902;
- }
- </style>
-</head>
-<body>
- <div class="logo">
- <img src="logo2.png" alt="MicroPie logo">
- </div>
- <div class="body">
- <h1>Welcome</h1>
- <p><strong>MicroPie is an ultra-lightweight Python web framework</strong> that gets out of your way, letting you build fast and dynamic web apps with ease. With built-in Jinja2 templates, simple routing, and WSGI support, it’s the perfect choice for developers who value speed and simplicity. MicroPie was inspired by <a href="https://cherrypy.dev/">CherryPy</a> and is licensed under the BSD three-clause license.</p>
-
- <h2>MicroPie is Fun</h2>
- <pre><code>
-<span class="c2">from</span> MicroPie <span class="c2">import</span> Server
-
-<span class="c2">class</span> MyApp(<span class="c9">Server</span>):
-
- <span class="c2">def</span> index(<span class="c9">self</span>):
- return <span class="c9">'Hello World!'</span>
-
-MyApp().run()
- </code></pre>
-
- <h2>And Easy to Install</h2>
- <pre><code>
-<span class="c2">$</span> pip install <span class="c9">micropie</span>
- </code></pre>
-
- <h2>More Information</h2>
- <p> MicroPie was written by <a href="https://patx.github.io">Harrison Erd</a>. If you would like to file an issue report or fork the project, check out the <a href="https://github.com/patx/micropie">Github project page</a>. You can view examples and documentation <a href="https://github.com/patx/micropie/blob/main/README.md">here</a>. You can also take a look at MicroPie <a href="https://pypi.python.org/pypi/MicroPie">on PyPI</a>.</p>
-
- <a href="https://github.com/patx/micropie">
- <img style="position: fixed; top: 0; right: 0; border: 0;" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_red_aa0000.png" alt="Fork me on GitHub">
- </a>
- </div>
-</body>
-</html>
-
diff --git a/docs/logo.png b/docs/logo.png
new file mode 100644
index 0000000..20eb33f
Binary files /dev/null and b/docs/logo.png differ
diff --git a/docs/logo2.png b/docs/logo2.png
deleted file mode 100644
index e2cd8a6..0000000
Binary files a/docs/logo2.png and /dev/null differ
diff --git a/docs/new.html b/docs/new.html
new file mode 100644
index 0000000..7c2b48e
--- /dev/null
+++ b/docs/new.html
@@ -0,0 +1,139 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="shortcut icon" href="https://cherrypy.dev/images/favicon.gif" type="image/x-icon">
+ <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
+ <title>MicroPie - An ultra-micro Python web framework</title>
+ <style>
+ body {
+ font-family: 'Poppins', sans-serif;
+ margin: 0;
+ padding: 0;
+
+ color: #333;
+ }
+ .container {
+ max-width: 800px;
+ margin: auto;
+ margin-top: auto;
+ margin-bottom: auto;
+ background: #fff;
+ padding: 40px;
+ border-radius: 15px;
+ text-align: center;
+ }
+ h1, h2 {
+ color: #B22222;
+ font-weight: 600;
+ }
+ h2 {
+ text-align: left;
+ }
+ p {
+ font-size: 18px;
+ line-height: 1.6;
+ color: #555;
+ }
+ a {
+ color: #B22222;
+ text-decoration: none;
+ font-weight: 600;
+ transition: color 0.3s ease;
+ }
+ a:hover {
+ border: 1px solid #B22222;
+ border-radius: 30px;
+ }
+ pre {
+ background: #f5f2f0;
+ padding: 20px;
+ border-radius: 10px;
+ text-align: left;
+ overflow-x: auto;
+ font-size: 1.1em;
+ }
+ .logo img {
+ max-width: 600px;
+ }
+ span.c2 {
+ color: #8F5902;
+ }
+ span.c9 {
+ color: #B22222;
+ }
+ .github-banner img {
+ position: fixed;
+ top: 0;
+ right: 0;
+ border: 0;
+ }
+ .button {
+ display: inline-block;
+ background: #B22222;
+ color: #fff;
+ padding: 15px 30px;
+ border-radius: 30px;
+ font-size: 18px;
+ font-weight: 600;
+ transition: background 0.3s ease;
+ }
+ .button:hover {
+ background: white;
+ border: 2px solid #B22222;
+ color: #B22222
+ }
+ @media (max-width: 768px) {
+ .container {
+ width: 100%;
+ padding: 20px;
+ }
+ .logo img {
+ max-width: 100%;
+ }
+ .button {
+ max-width: 100%;
+ text-align: center;
+ }
+ .github-banner {
+ display: none;
+ }
+ }
+ </style>
+</head>
+<body>
+ <div class="container">
+ <div class="logo">
+ <img src="logo.png" alt="MicroPie logo">
+ </div>
+ <p><strong>MicroPie is an ultra-lightweight Python web framework</strong> that gets out of your way, letting you build fast and dynamic web apps with ease.
+ Inspired by <a href="https://cherrypy.dev/">CherryPy</a> and licensed under the BSD three-clause license.</p>
+
+ <h2>MicroPie is Fun</h2>
+ <pre><code>
+<span class="c2">from</span> MicroPie <span class="c2">import</span> Server
+
+<span class="c2">class</span> MyApp(<span class="c9">Server</span>):
+
+ <span class="c2">def</span> index(<span class="c9">self</span>):
+ return <span class="c9">'Hello World!'</span>
+
+MyApp().run()
+ </code></pre>
+
+ <h2> And Easy to Install</h2>
+ <pre><code><span class="c2">$</span> pip install <span class="c9">micropie</span></code></pre>
+
+ <p><br><br>
+ <a href="https://github.com/patx/micropie" class="button">View source code, examples and documentation on GitHub</a>
+ </p>
+ </div>
+ <div class="github-banner">
+ <a href="https://github.com/patx/micropie">
+ <img src="https://github.blog/wp-content/uploads/2008/12/forkme_right_red_aa0000.png" alt="Fork me on GitHub">
+ </a>
+ </div>
+</body>
+</html>
+
diff --git a/examples/twutr/twutr.py b/examples/twutr/twutr.py
index 5188666..92f8bb6 100644
--- a/examples/twutr/twutr.py
+++ b/examples/twutr/twutr.py
@@ -170,6 +170,7 @@ class Twutr(Server):
"""Displays a specific user's messages."""
logged_in = self.session.get('logged_in')
current_user = self.session.get('user_id')
+ username = escape(username)
# Determine if current_user is following, is the same user, or is not logged in
if not logged_in or not current_user:
@@ -205,7 +206,9 @@ class Twutr(Server):
if not self.session.get('logged_in'):
return self.redirect('/login')
+ username = escape(username)
current_user = self.session.get('user_id')
+
if username == current_user:
return "You cannot follow yourself"
@@ -218,12 +221,13 @@ class Twutr(Server):
return self.redirect('/login')
current_user = self.session.get('user_id')
- update_follow_relationship(current_user, username, follow=False)
+ update_follow_relationship(current_user, escape(username), follow=False)
return self.redirect(f'/user/{username}')
def list_followers(self, username):
"""Displays the list of followers for a given user."""
+ username = escape(username)
user_data = get_user_data(username)
if not user_data:
return "User not found", 404
@@ -238,6 +242,7 @@ class Twutr(Server):
def list_following(self, username):
"""Displays the list of users that a given user is following."""
+ username = escape(username)
user_data = get_user_data(username)
if not user_data:
return "User not found", 404
@@ -280,8 +285,8 @@ class Twutr(Server):
return self.redirect('/')
if self.request == 'POST':
- username = self.body_params.get('username', [''])[0].strip()
- password = self.body_params.get('password', [''])[0].strip()
+ username = escape(self.body_params.get('username', [''])[0].strip())
+ password = escape(self.body_params.get('password', [''])[0].strip())
if not username or not password:
return self.render_template('login.html', error="Fields cannot be empty", session=self.session)
@@ -302,19 +307,23 @@ class Twutr(Server):
return self.redirect('/')
if self.request == 'POST':
- username = self.body_params.get('username', [''])[0].strip()
- password = self.body_params.get('password', [''])[0].strip()
-
- if username and password:
- db.set(username, {
- 'username': username,
- 'password': password,
- 'messages': [],
- 'followers': [],
- 'following': []
- })
- db.save()
- return self.redirect('/login')
+ username = escape(self.body_params.get('username', [''])[0].strip())
+ password = escape(self.body_params.get('password', [''])[0].strip())
+
+ if not username or not password:
+ return self.render_template('login.html', error="Fields cannot be empty", session=self.session)
+ if db.get(username):
+ return self.render_template('register.html', session=self.session, error="Username already taken.")
+
+ db.set(username, {
+ 'username': username,
+ 'password': password,
+ 'messages': [],
+ 'followers': [],
+ 'following': []
+ })
+ db.save()
+ return self.redirect('/login')
return self.render_template('register.html', session=self.session)