Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
from flask import Flask
from markupsafe import escape
from flask import url_for
from flask import render_template
from flask import request
from flask import redirect
from flask import abort
from flask import make_response
import sqlite3
app = Flask(__name__)
@app.route("/create")
def create():
con = sqlite3.connect('mydatabase.db')
con.execute('CREATE TABLE IF NOT EXISTS books (name TEXT, id INT)')
con.close()
return "<h1>Table created successfully</h1>"
@app.route("/add")
def add_book():
con = sqlite3.connect('mydatabase.db')
cur = con.cursor()
cname='Faye'
cid=10000
cur.execute("INSERT INTO books (name,id) VALUES (?,?)",(cname,cid) )
con.commit()
con.close()
return "<h1>added books</h1>"
@app.route("/")
def top():
con = sqlite3.connect("mydatabase.db")
con.row_factory = sqlite3.Row
cur = con.cursor()
cur.execute("SELECT * from books")
rows = cur.fetchall();
return render_template("bookss.html",rows = rows)
@app.route('/')
def index():
username = request.cookies.get('username')
@app.route('/logged_i')
def logged_in():
resp = make_response(render_template('loggedin.html'))
resp.set_cookie('username', 'the username')
return resp