Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8f4c620
Update README.md
jesus7110 Sep 30, 2021
09137ca
Update README.md
jesus7110 Sep 30, 2021
5df15b7
Update README.md
Saggittarius-A Sep 30, 2021
99834d9
Added comments on Readme.md
topperkp Sep 30, 2021
344727d
Merge pull request #3 from topperkp/master
kavyanshpandey Sep 30, 2021
ce67277
Update README.md
akhil-maker Sep 30, 2021
c6590b7
Merge pull request #1 from jesus7110/master
kavyanshpandey Sep 30, 2021
d8de8e3
Merge pull request #2 from Saggittarius-A/patch-1
kavyanshpandey Sep 30, 2021
ac8d4ee
Merge pull request #4 from akhil-maker/master
kavyanshpandey Sep 30, 2021
0e9ddaa
Update contact.html
bhattji007 Oct 2, 2021
9558191
Update README.md
sangeeta874 Oct 2, 2021
d5ce329
Merge pull request #24 from sangeeta874/patch-1
kavyanshpandey Oct 3, 2021
1730e4e
Merge pull request #16 from bhattji007/patch-1
kavyanshpandey Oct 3, 2021
1c05b05
Updated readme.md added new lines
ybshubham Oct 5, 2021
43c5564
Merge pull request #33 from ybshubham/master
kavyanshpandey Oct 5, 2021
20f0a67
Updated gitignore file
intangible-explorer Oct 5, 2021
af336b2
Merge pull request #34 from intangible-explorer/master
kavyanshpandey Oct 5, 2021
6ad0547
added about-us page in blog site
sujoy-coder Oct 5, 2021
8de990d
added about.html
sujoy-coder Oct 5, 2021
4023382
Merge pull request #40 from sujoy-coder/dev
kavyanshpandey Oct 5, 2021
9b8110e
Update main.css
joyal7701 Oct 6, 2021
c68496a
Merge pull request #41 from joyal7701/patch-1
kavyanshpandey Oct 6, 2021
2ef3af2
naming convention for constant PORT number
jatinsajwan3841 Oct 9, 2021
4068734
Merge pull request #52 from jatinsajwan3841/patch-1
kavyanshpandey Oct 9, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# created by virtualenv automatically
*
bin/
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
# python-flask-Web-APP

### This is a web application made with python-Flask, and SQLLITE3 used as backend.
### This is a Web Application made with python-Flask, and SQLLITE3 used as backend.

### Project View.
### Project View

## Use Cases
1. User can add any number of blogpost.
2. User an also edit their blog
3. User can also delete posts by clicking on red button.

<br>
<br>

![alt text](https://github.com/kavyanshpandey/python-flask-blog/blob/master/pic1.png)

<br>
<br>
### How to Run.

-> Clone this repo
-> Install dependepcies
-> Run "app.py"


<br>
<br>
65 changes: 36 additions & 29 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask,jsonify, render_template, request,redirect
from flask import Flask, jsonify, render_template, request, redirect
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

Expand All @@ -7,48 +7,60 @@
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///posts.db'
db = SQLAlchemy(app)


class BlogPost(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable = False)
Content = db.Column(db.Text, nullable = False)
Author = db.Column(db.String(20), nullable = False, default = 'Unknown')
date_posted = db.Column(db.DateTime, nullable = False, default= datetime.utcnow)
title = db.Column(db.String(100), nullable=False)
Content = db.Column(db.Text, nullable=False)
Author = db.Column(db.String(20), nullable=False, default='Unknown')
date_posted = db.Column(db.DateTime, nullable=False,
default=datetime.utcnow)

def __repr__(self):
return 'Blog post ' + str(self.id)


all_posts = [
{
'title': 'Post1',
'Content':'This is the content of post 1',
'Author':'kavyansh'
'Content': 'This is the content of post 1',
'Author': 'kavyansh'
},
{
'title': 'Post2',
'Content':'This is the content of post 2',
'Content': 'This is the content of post 2',
# 'Author': ''
}
]

@app.route('/', methods =['GET'])

@app.route('/', methods=['GET'])
def homepage():
return render_template('index.html')


@app.route('/aboutus', methods=['GET'])
def aboutpage():
return render_template('about.html')


@app.route('/contactus', methods=['GET'])
def contact():
return render_template('contact.html')
return render_template('contact.html')

@app.route('/posts/newposts', methods=['GET','POST'])

@app.route('/posts/newposts', methods=['GET', 'POST'])
def addPosts():
if request.method == 'POST':
if request.method == 'POST':
post_title = request.form['title']
post_content = request.form['Content']
post_author = request.form['Author']

if post_author == '':
post_author = 'Unknown'

new_post = BlogPost(title=post_title, Content=post_content, Author=post_author)
new_post = BlogPost(
title=post_title, Content=post_content, Author=post_author)

db.session.add(new_post)

Expand All @@ -57,14 +69,12 @@ def addPosts():
return redirect('/posts')

else:
return render_template('add_posts.html')
return render_template('add_posts.html')




@app.route('/posts',methods =['GET', 'POST'])
@app.route('/posts', methods=['GET', 'POST'])
def posts():
if request.method == 'POST':
if request.method == 'POST':

post_title = request.form['title']
post_content = request.form['Content']
Expand All @@ -73,32 +83,29 @@ def posts():
if post_author == '':
post_author = 'Unknown'

new_post = BlogPost(title=post_title, Content=post_content, Author=post_author)
new_post = BlogPost(
title=post_title, Content=post_content, Author=post_author)

db.session.add(new_post)

db.session.commit()

return redirect('/posts')


else:
all_posts = BlogPost.query.order_by(BlogPost.date_posted).all()
return render_template('posts.html', posts = all_posts)
return render_template('posts.html', posts=all_posts)




@app.route('/posts/delete/<int:id>',methods=['GET','POST'])
@app.route('/posts/delete/<int:id>', methods=['GET', 'POST'])
def deletePost(id):
post_id = BlogPost.query.get(id)
db.session.delete(post_id)
db.session.commit()
return redirect('/posts')



@app.route('/posts/edit/<int:id>', methods=['GET','POST'])
@app.route('/posts/edit/<int:id>', methods=['GET', 'POST'])
def editPost(id):
post_id = BlogPost.query.get_or_404(id)
if request.method == 'POST':
Expand All @@ -110,10 +117,10 @@ def editPost(id):

return redirect('/posts')


else:
return render_template('edit.html', post = post_id)
return render_template('edit.html', post=post_id)


if __name__ == "__main__":
app.run(debug=True, port= 5000)
PORT = 5000
app.run(debug=True, port=PORT)
Empty file added posts.db
Empty file.
3 changes: 2 additions & 1 deletion static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ body {
padding: 1rem;
margin: 2rem auto;
max-width: 40rem;
} */
background-color: red;
} */
28 changes: 28 additions & 0 deletions templates/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends 'base.html' %}


{% block head %}
<title>About | Python Warrior</title>

{% endblock %}


{% block body %}
<h1>About Us</h1>

<div>

<div class="bg-light p-5 rounded">
<div class="col-sm-8 mx-auto ">
<h1>Welcome to My Blog..</h1>
<h3>Author : kavyansh</h3>
<br>
<p>Hello I am Kavyansh.</p>
<p>Welcome to my blog. Here I post my thoughts like my experience in colleges and now in corporate. I also post technical contents there.</p>
<br>
<a class="btn btn-success" href="/">Back</a>
</div>
</div>
</div>
</div>
{% endblock %}
5 changes: 4 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
<a class="nav-link active" aria-current="page" href="/posts">All posts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/contactus">Contact us</a>
<a class="nav-link" href="/aboutus">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/contactus">Contact Us</a>
</li>
</ul>
<span class="navbar-text">
Expand Down
7 changes: 6 additions & 1 deletion templates/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ <h1>You can connect with me</h1>
<a class="btn btn-link" href="https://www.twitter.com/KavyanshPandey" role="button">twitter
&raquo;</a>
</p>
<p>Connect with me on linkedin.</p>
<p>
<a class="btn btn-link" href="https://www.linkedin.com" role="button">LinkedIn
&raquo;</a>
</p>
</div>
</div>
</div>
</div>
{% endblock %}
{% endblock %}