├── .gitignore ├── LICENSE ├── README.md ├── app.py ├── requirements.txt └── templates ├── edit_post.html ├── index.html ├── new_post.html └── templates └── new_post.html /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # Installer logs 29 | pip-log.txt 30 | pip-delete-this-directory.txt 31 | 32 | # Unit test / coverage reports 33 | htmlcov/ 34 | .tox/ 35 | .nox/ 36 | .coverage 37 | .coverage.* 38 | .cache 39 | nosetests.xml 40 | coverage.xml 41 | *.cover 42 | .hypothesis/ 43 | 44 | # Translations 45 | *.mo 46 | *.pot 47 | 48 | # Django stuff: 49 | *.log 50 | local_settings.py 51 | db.sqlite3 52 | 53 | # Flask stuff: 54 | instance/ 55 | .webassets-cache 56 | 57 | # Sphinx documentation 58 | docs/_build/ 59 | doc/source/_build/ 60 | 61 | # PyBuilder 62 | target/ 63 | 64 | # Jupyter Notebook 65 | .ipynb_checkpoints 66 | 67 | # IPython 68 | profile_default/ 69 | ipython_config.py 70 | 71 | # pyenv 72 | .python-version 73 | 74 | # celery beat schedule file 75 | celerybeat-schedule 76 | celerybeat.pid 77 | 78 | # SageMath parsed files 79 | *.sage.py 80 | 81 | # dotenv 82 | .env 83 | .venv 84 | 85 | # virtualenv 86 | venv/ 87 | ENV/ 88 | env.bak/ 89 | env/ 90 | 91 | # Spyder project settings 92 | .spyderproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | 103 | # Pyre type checker 104 | .pyre/ 105 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SimpleBlog 2 | 3 | SimpleBlog is a simple Python-based web application using Flask that allows users to create, read, update, and delete blog posts. 4 | 5 | ## Features 6 | 7 | - Create new blog posts. 8 | - View all blog posts. 9 | - Edit existing blog posts. 10 | - Delete blog posts. 11 | 12 | ## Installation 13 | 14 | 1. Clone the repository: 15 | ```bash 16 | git clone https://github.com/YOUR_USERNAME/SimpleBlog.git 17 | cd SimpleBlog 18 | ``` 19 | 20 | 2. Create a virtual environment and activate it: 21 | ```bash 22 | python -m venv venv 23 | source venv/bin/activate # On Windows use `venv\Scripts\activate` 24 | ``` 25 | 26 | 3. Install the required packages: 27 | ```bash 28 | pip install -r requirements.txt 29 | ``` 30 | 31 | 4. Run the application: 32 | ```bash 33 | python app.py 34 | ``` 35 | 36 | 5. Open your web browser and go to `http://127.0.0.1:5000`. 37 | 38 | ## License 39 | 40 | This project is licensed under the MIT License. 41 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request, redirect, url_for 2 | from flask_sqlalchemy import SQLAlchemy 3 | 4 | app = Flask(__name__) 5 | app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///blog.db' 6 | app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False 7 | db = SQLAlchemy(app) 8 | 9 | class Post(db.Model): 10 | id = db.Column(db.Integer, primary_key=True) 11 | title = db.Column(db.String(100), nullable=False) 12 | content = db.Column(db.Text, nullable=False) 13 | 14 | @app.before_first_request 15 | def create_tables(): 16 | db.create_all() 17 | 18 | @app.route('/') 19 | def index(): 20 | posts = Post.query.all() 21 | return render_template('index.html', posts=posts) 22 | 23 | @app.route('/post/new', methods=['GET', 'POST']) 24 | def new_post(): 25 | if request.method == 'POST': 26 | title = request.form['title'] 27 | content = request.form['content'] 28 | new_post = Post(title=title, content=content) 29 | db.session.add(new_post) 30 | db.session.commit() 31 | return redirect(url_for('index')) 32 | return render_template('new_post.html') 33 | 34 | @app.route('/post/edit/', methods=['GET', 'POST']) 35 | def edit_post(id): 36 | post = Post.query.get_or_404(id) 37 | if request.method == 'POST': 38 | post.title = request.form['title'] 39 | post.content = request.form['content'] 40 | db.session.commit() 41 | return redirect(url_for('index')) 42 | return render_template('edit_post.html', post=post) 43 | 44 | @app.route('/post/delete/') 45 | def delete_post(id): 46 | post = Post.query.get_or_404(id) 47 | db.session.delete(post) 48 | db.session.commit() 49 | return redirect(url_for('index')) 50 | 51 | if __name__ == '__main__': 52 | app.run(debug=True) 53 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask 2 | Flask-SQLAlchemy 3 | -------------------------------------------------------------------------------- /templates/edit_post.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Edit Post 7 | 8 | 45 | 46 | 47 |
48 |

Edit Post

49 |
50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SimpleBlog 7 | 8 | 47 | 48 | 49 |
50 |

SimpleBlog

51 | Create New Post 52 | {% for post in posts %} 53 |
54 |

{{ post.title }}

55 |

{{ post.content }}

56 | Edit 57 | Delete 58 |
59 | {% endfor %} 60 |
61 | 62 | 63 | -------------------------------------------------------------------------------- /templates/new_post.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | New Post 7 | 8 | 45 | 46 | 47 |
48 |

New Post

49 |
50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /templates/templates/new_post.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | New Post 7 | 8 | 45 | 46 | 47 |
48 |

New Post

49 |
50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | --------------------------------------------------------------------------------