You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently building a flask web application using Microsoft Azure. The basic idea is just a blog for my school which I'm doing as a project. For this web application, I have two html pages. A home page where people just chat and a calendar page. yes not the best ideas but it's sufficient. What i'm wondering is how i select a database for each html page. Since it's like a forum blog type page, I already have the form and the script for that ready but when I enter something, it shows up for all the pages. I've made two databases, database.db for the home page and calendar.db for the calendar page. So far, everything i've been submitting into the forms is going into database.db and not calendar.db for the calendar.html page. So, i've made the database for the calendar page and made a table for it but can't seem to connect it to calendar.db.
Here is my code:
app.py
from flask_cors import CORS
from models import create_post, get_posts
app = Flask(__name__)
CORS(app)
u/app.route('/', methods=['GET','POST'])
def index():
if request.method == 'GET':
pass
if request.method == 'POST':
name = request.form.get('name')
post = request.form.get('post')
create_post(name, post)
posts = get_posts()
return render_template('index.html', posts=posts)
u/app.route('/calendar.html', methods=['GET','POST'])
def calendar():
if request.method == 'GET':
pass
if request.method == 'POST':
name = request.form.get('name')
post = request.form.get('post')
create_post(name, post)
posts = get_posts()
return render_template('calendar.html', posts=posts)
if __name__ == '__main__':
app.run(host="0.0.0.0", port=80)
and then models.py
import sqlite3 as sql
from os import path
ROOT = path.dirname(path.relpath((__file__)))
def create_post(name,content):
con = sql.connect(path.join(ROOT, 'database.db'))
cur = con.cursor()
cur.execute('insert into posts (name, content) values(?, ?)', (name, content))
con.commit()
con.close()
def get_posts():
con = sql.connect(path.join(ROOT, 'database.db'))
cur = con.cursor()
cur.execute('select * from posts')
posts = cur.fetchall()
return posts
It would be great if you guys could help me. I've made another models.py with different variables and connected them to calendar.html/calendar.db but that hasn't work. I've done a lot of things and followed the same steps i got database.db to work but I can't figure it out.
Thank you
The text was updated successfully, but these errors were encountered:
I'm currently building a flask web application using Microsoft Azure. The basic idea is just a blog for my school which I'm doing as a project. For this web application, I have two html pages. A home page where people just chat and a calendar page. yes not the best ideas but it's sufficient. What i'm wondering is how i select a database for each html page. Since it's like a forum blog type page, I already have the form and the script for that ready but when I enter something, it shows up for all the pages. I've made two databases, database.db for the home page and calendar.db for the calendar page. So far, everything i've been submitting into the forms is going into database.db and not calendar.db for the calendar.html page. So, i've made the database for the calendar page and made a table for it but can't seem to connect it to calendar.db.
Here is my code:
app.py
and then models.py
and finally my html page for the calendar :
my html is not the best.
It would be great if you guys could help me. I've made another models.py with different variables and connected them to calendar.html/calendar.db but that hasn't work. I've done a lot of things and followed the same steps i got database.db to work but I can't figure it out.
Thank you
The text was updated successfully, but these errors were encountered: