Permalink
Cannot retrieve contributors at this time
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?
website_project/testing.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
49 lines (42 sloc)
1.22 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |