Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Blogging Platform #19

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
44 changes: 44 additions & 0 deletions Basic Blogging Platform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Simple Blogging Platform

A basic blogging platform created using Python, allowing users to create, edit, and view blog posts.

## Table of Contents
- [Features](#features)
- [Usage](#usage)
- [Enhanced CSS](#enhanced-css)

---

## Features

- Users can create and edit blog posts.
- Posts are displayed with a title and content.
- Smooth transitions and improved CSS for a better user experience.
- Responsive design.

## Usage

1. Browse existing blog posts on the main page.
2. Click on "Create a new post" to add a new blog post.
3. Enter a title and content for your post, then click "Create Post."
4. Your new post will be displayed on the main page.
5. Click on any post to view its details or edit it.

## Enhanced CSS

The CSS has been enhanced to provide smooth transitions, improved background color, and better alignment for a more visually pleasing user experience.

### Features of Enhanced CSS

- Smooth transitions for elements.
- Improved background color.
- Enhanced alignment of text content.
- Responsive design.

Feel free to further customize the CSS to match your desired design.

---

## Developed By
Eshaalakshmi D S : https://github.com/EshaalakshmiDS

56 changes: 56 additions & 0 deletions Basic Blogging Platform/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import http.server
import socketserver
from urllib.parse import parse_qs, urlparse

# Store blog posts in a list (in-memory storage, not suitable for production)
posts = []

class BlogHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(b'Welcome to My Blog\n')
self.wfile.write(b'<ul>\n')
for post in posts:
self.wfile.write(b'<li>\n')
self.wfile.write(f'<h2>{post["title"]}</h2>\n'.encode('utf-8'))
self.wfile.write(f'<p>{post["content"]}</p>\n'.encode('utf-8'))
self.wfile.write(b'</li>\n')
self.wfile.write(b'</ul>\n')
self.wfile.write(b'<a href="/create">Create a new post</a>\n')
elif self.path == '/create':
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(b'Create a New Blog Post\n')
self.wfile.write(b'<form method="POST">\n')
self.wfile.write(b'<label for="title">Title</label>\n')
self.wfile.write(b'<input type="text" name="title" required><br>\n')
self.wfile.write(b'<label for="content">Content</label>\n')
self.wfile.write(b'<textarea name="content" rows="4" required></textarea><br>\n')
self.wfile.write(b'<button type="submit">Create Post</button>\n')
self.wfile.write(b'</form>\n')
else:
self.send_response(404)
self.end_headers()
self.wfile.write(b'Not Found')

def do_POST(self):
content_length = int(self.headers['Content-Length'])
post_data = self.rfile.read(content_length).decode('utf-8')
post_params = parse_qs(post_data)
title = post_params['title'][0]
content = post_params['content'][0]
posts.append({'title': title, 'content': content})
self.send_response(303)
self.send_header('Location', '/')
self.end_headers()

if __name__ == '__main__':
PORT = 8080

with socketserver.TCPServer(("", PORT), BlogHandler) as httpd:
print(f"Serving at port {PORT}")
httpd.serve_forever()
67 changes: 67 additions & 0 deletions Basic Blogging Platform/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
body {
font-family: Arial, sans-serif;
background: linear-gradient(to bottom, #f0f0f0, #e0e0e0);
margin: 0;
padding: 0;
}

h1 {
text-align: center;
background-color: #007acc;
color: white;
padding: 20px;
margin: 0;
}

ul {
list-style-type: none;
padding: 0;
text-align: center;
}

li {
background-color: #fff;
border: 1px solid #ddd;
border-radius: 5px;
margin: 10px;
padding: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: transform 0.2s, box-shadow 0.2s, background-color 0.2s;
cursor: pointer;
}

li:hover {
transform: scale(1.05);
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.2);
background-color: #f5f5f5; /* Lighter background color on hover */
}

h2 {
font-size: 24px;
margin: 10px 0;
color: #333;
}

p {
font-size: 16px;
color: #555; /* Slightly darker text color */
margin: 10px 0;
text-align: left;
}

a {
display: block;
text-align: center;
background-color: #007acc;
color: white;
padding: 10px;
text-decoration: none;
margin: 20px auto;
width: 150px;
border-radius: 5px;
transition: background-color 0.2s;
}

a:hover {
background-color: #0058a9;
}
17 changes: 17 additions & 0 deletions Basic Blogging Platform/html/create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>Create a Post</title>
<link rel="stylesheet" type="text/css" href="/Basic Blogging Platform/css/style.css">
</head>
<body>
<h1>Create a New Blog Post</h1>
<form method="POST">
<label for="title">Title</label>
<input type="text" name="title" required><br>
<label for="content">Content</label>
<textarea name="content" rows="4" required></textarea><br>
<button type="submit">Create Post</button>
</form>
</body>
</html>
19 changes: 19 additions & 0 deletions Basic Blogging Platform/html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>My Blog</title>
<link rel="stylesheet" type="text/css" href="/Basic Blogging Platform/css/style.css">
</head>
<body>
<h1>Welcome to My Blog</h1>
<ul>
{% for post in posts %}
<li>
<h2>{{ post.title }}</h2>
<p>{{ post.content }}</p>
</li>
{% endfor %}
</ul>
<a href="html\create.html">Create a new post</a>
</body>
</html>