Dec-10-2017, 04:36 PM
(This post was last modified: Dec-10-2017, 04:37 PM by JerryMotov.)
I want to get the data from my sqlite database using peewee
Currently I am trying to do this on this way:
Currently I am trying to do this on this way:
data_list = [] for email in Check_history.select(): data_list.append([Check_history.email, Check_history.valid_or_invalid]) return data_listBut this returns an object and not a string :(
Output:<class 'sql.Check_history'> SELECT "t1"."id", "t1"."email", "t1"."valid_or_invalid" FROM "check_history" AS t1 []
<peewee.StringExpression object at 0x7fbc4a9e85c0>
<peewee.StringExpression object at 0x7fbc4dc410b8>
<peewee.StringExpression object at 0x7fbc4dc410f0>
<peewee.StringExpression object at 0x7fbc4dc41048>
My main scriptfrom flask import Flask, render_template, request import sqlite3 from peewee import * from functions import * from sql import * app = Flask(__name__, template_folder='.') @app.route('/') def no_mail(): return render_template('index.html') @app.route('/', methods=['POST']) def check_input(): print("POSTING") email = request.form['text'] outcome = check_email(email) set_data(email, outcome[0]) result_set = get_data() return render_template('index.html', result = outcome[1]) """ @app.route('/<email>') def send_check_mail(email): print("POSTING------") outcome = check_email(email) set_data(email, outcome[0]) result_set = get_data() return render_template('index.html', result = outcome[1]) """ if __name__ == "__main__": app.run(host="0.0.0.0", port=8000) init_database()Sql.py the file that creates the database ect..
""" This is the file that creates the database """ from peewee import * import sqlite3 # Create the database db = SqliteDatabase('check_history.db') class Check_history(Model): """Create the columns""" email = CharField(max_length = 100) valid_or_invalid = CharField(max_length = 10) class Meta: """ Tell the class Check_history that The data belongs to the database check_history """ database = db def set_data(email, valid_invalid): #init_database() data = Check_history.create(email = email, valid_or_invalid = valid_invalid[1]) data.save() def get_data(): #init_database() data_list = [] print(Check_history.select()) for email in Check_history.select(): data_list.append([Check_history.email, Check_history.valid_or_invalid]) return data_list def init_database(): db.connect() db.create_tables([Check_history], safe = True)