diff --git a/.gitignore b/.gitignore index ede80b8..2be620c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ # created by virtualenv automatically * +bin/ diff --git a/README.md b/README.md index 7f92142..20f0de3 100644 --- a/README.md +++ b/README.md @@ -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.

![alt text](https://github.com/kavyanshpandey/python-flask-blog/blob/master/pic1.png) + +
+
+### How to Run. + + -> Clone this repo + -> Install dependepcies + -> Run "app.py" + + +
+
diff --git a/app.py b/app.py index 015cfa9..d35fba1 100644 --- a/app.py +++ b/app.py @@ -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 @@ -7,40 +7,51 @@ 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'] @@ -48,7 +59,8 @@ def addPosts(): 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) @@ -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'] @@ -73,7 +83,8 @@ 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) @@ -81,15 +92,12 @@ def posts(): 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/',methods=['GET','POST']) +@app.route('/posts/delete/', methods=['GET', 'POST']) def deletePost(id): post_id = BlogPost.query.get(id) db.session.delete(post_id) @@ -97,8 +105,7 @@ def deletePost(id): return redirect('/posts') - -@app.route('/posts/edit/', methods=['GET','POST']) +@app.route('/posts/edit/', methods=['GET', 'POST']) def editPost(id): post_id = BlogPost.query.get_or_404(id) if request.method == 'POST': @@ -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) \ No newline at end of file + PORT = 5000 + app.run(debug=True, port=PORT) diff --git a/posts.db b/posts.db new file mode 100644 index 0000000..e69de29 diff --git a/static/css/main.css b/static/css/main.css index 4192a4e..477f887 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -10,4 +10,5 @@ body { padding: 1rem; margin: 2rem auto; max-width: 40rem; -} */ \ No newline at end of file + background-color: red; +} */ diff --git a/templates/about.html b/templates/about.html new file mode 100644 index 0000000..238727b --- /dev/null +++ b/templates/about.html @@ -0,0 +1,28 @@ +{% extends 'base.html' %} + + +{% block head %} +About | Python Warrior + +{% endblock %} + + +{% block body %} +

About Us

+ +
+ +
+
+

Welcome to My Blog..

+

Author : kavyansh

+
+

Hello I am Kavyansh.

+

Welcome to my blog. Here I post my thoughts like my experience in colleges and now in corporate. I also post technical contents there.

+
+ Back +
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index b6cfa00..84d727b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -24,7 +24,10 @@ All posts + diff --git a/templates/contact.html b/templates/contact.html index 7974ea1..c3c4674 100644 --- a/templates/contact.html +++ b/templates/contact.html @@ -28,8 +28,13 @@

You can connect with me

twitter »

+

Connect with me on linkedin.

+

+ LinkedIn + » +

-{% endblock %} \ No newline at end of file +{% endblock %}