Дорогие друзья столкнулся с такой проблемой есть модель katalog
class Katalog (db.Model):
id = db.Column(db.Integer, primary_key=True)
name_tovar = db.Column(db.String(150))
kat = db.Column(db.String(150))
artikul = db.Column(db.String(150))
ostatok = (db.Integer)
price = (db.Float(50, 2))
img_links = (db.String(250))
у него есть поле price с типом данных float так вот пытаюсь вывести в шаблоне выдает следующее
import os
from flask import Flask, render_template, flash, redirect, url_for, session, request, logging
from flask_sqlalchemy import SQLAlchemy
from wtforms import Form, StringField, TextAreaField, PasswordField, validators
from passlib.hash import sha256_crypt
from functools import wraps
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://webadmin:OELdtt45148@136.144.31.16/postgres'
app.secret_key = os.urandom(24)
db = SQLAlchemy(app)
class Klient (db.Model):
id = db.Column(db.Integer, primary_key=True)
inn = db.Column(db.String(50))
password = db.Column(db.String(50))
class Katalog (db.Model):
id = db.Column(db.Integer, primary_key=True)
name_tovar = db.Column(db.String(150))
kat = db.Column(db.String(150))
artikul = db.Column(db.String(150))
ostatok = (db.Integer)
price = (db.Float(50, 2))
img_links = (db.String(250))
# User login
@app.route('/', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
# Get Form Fields
username = request.form['username']
password_candidate = request.form['password']
# Create cursor
#cur = mysql.connection.cursor()
result = Klient.query.filter_by(inn=username).first()
# Get user by username
#result = cur.execute("SELECT * FROM users WHERE username = %s", [username])
if result:
# Get stored hash
#data = cur.fetchone()
data = result.password
password = data
#print(password)
#print('ii',password_candidate)
#print('iiu', username)
# Compare Passwords
#if sha256_crypt.verify(password_candidate, password):
if password_candidate == password:
# Passed
session['logged_in'] = True
session['username'] = username
flash('You are now logged in', 'success')
return redirect(url_for('test1'))
else:
error = 'Invalid login'
return render_template('index.html', error=error)
# Close connection
#cur.close()
else:
error = 'Username not found'
return render_template('index.html', error=error)
return render_template('index.html')
# Check if user logged in
def is_logged_in(f):
@wraps(f)
def wrap(*args, **kwargs):
if 'logged_in' in session:
return f(*args, **kwargs)
else:
flash('Unauthorized, Please login', 'danger')
return redirect(url_for('login'))
return wrap
# test login
@app.route('/test', methods=['GET', 'POST'])
@is_logged_in
def test1():
b1 = session ['username']
incomplete = Katalog.query.filter_by(kat='s').all()
return render_template('test.html', b1=b1, b2=incomplete)
# Logout
@app.route('/logout')
@is_logged_in
def logout():
session.clear()
flash('You are now logged out', 'success')
return redirect(url_for('login'))
if __name__ == '__main__':
app.run(debug='True')