Python Forum
Peewee returning objects and not strings..
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Peewee returning objects and not strings..
#1
Lightbulb 
I want to get the data from my sqlite database using peewee
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_list
But 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 script
from 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)
Reply


Messages In This Thread
Peewee returning objects and not strings.. - by JerryMotov - Dec-10-2017, 04:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create SQLite3 database with peewee Jim53_1980 2 739 Dec-20-2023, 02:38 PM
Last Post: buran
  Trying to understand strings and lists of strings Konstantin23 2 842 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 1,839 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Finding multiple strings between the two same strings Slither 1 2,569 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  lists, strings, and byte strings Skaperen 2 4,284 Mar-02-2018, 02:12 AM
Last Post: Skaperen
  peewee.OperationalError: no such table: JerryMotov 3 7,103 Dec-10-2017, 05:45 PM
Last Post: JerryMotov

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020