-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (26 loc) · 906 Bytes
/
app.py
File metadata and controls
33 lines (26 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sqlite3
from flask import Flask, render_template, request, url_for, flash, redirect, abort
# make a Flask application object called app
app = Flask(__name__)
app.config["DEBUG"] = True
app.config['SECRET_KEY'] = 'your secret key'
def get_db_connection():
conn = sqlite3.connect('database.db')
conn.row_factory = sqlite3.Row # This allows accessing columns by name
return conn
@app.route('/')
def index():
conn = get_db_connection()
posts = conn.execute('SELECT * FROM posts').fetchall()
conn.close()
return render_template('index.html', posts=posts)
@app.route('/create/', methods=('GET', 'POST'))
def create():
return "<h1>Create a Post<\h1>"
@app.route('/<int:id>/edit/', methods=('GET', 'POST'))
def edit(id):
return "<h1>Edit a Post<\h1>"
@app.route('/<int:id>/delete/', methods=('POST',))
def delete(id):
return
app.run(host="0.0.0.0", port=5001)