Я новичок во флеше и пытался создать сервер самостоятельно, и я столкнулся с проблемой с ошибкой работы SQLite.
Я не создал model.py (работает только с app.py), я должен сделать это?
Вот мой код и ошибка
from flask import Flask, request, jsonify
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
import os
import json
app = Flask(__name__)
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'crud.sqlite')
db = SQLAlchemy(app)
ma = Marshmallow(app)
class Info(db.Model):
id = db.Column(db.Integer, primary_key = True)
camId = db.Column(db.Integer, unique = False)
location = db.Column(db.String(80), unique=False)
isActive = db.Column(db.Integer, unique = False)
imgUrl = db.Column(db.String(120), unique= False)
gender = db.Column(db.String(80), unique=False)
age = db.Column(db.Integer, unique = False)
def __init__(self, camId, location, isActive, imgUrl, gender, age):
self.camId = camId
self.location = location
self.isActive = isActive
self.imgUrl = imgUrl
self.gender = gender
self.age = age
class InfoSchema(ma.Schema):
class Meta:
fields = ('camId', 'location', 'isActive', 'imgUrl', 'gender', 'age')
info_schema = InfoSchema()
info_schemas = InfoSchema(many=True)
@app.route('/')
def base():
# return (basedir)
for jsonfile in os.listdir(basedir+"/dbex/"):
if jsonfile[-4:] == "json":
with open(basedir+"/dbex/"+jsonfile) as data_result:
data = json.load(data_result)
return jsonify(data)
else:
return 'Nothing found'
@app.route('/api/create/cameraData', methods =["POST"])
def create_cameraData():
content = request.json
camId = content["camId"]
location = content["location"]
isActive = content["isActive"]
imgUrl = content["imgUrl"]
gender = content["gender"]
age = content["age"]
new_data = Info(camId, location, isActive, imgUrl, gender, age)
db.session.add(new_data)
db.session.commit()
return "success"
@app.route("/api/get/all", methods=["GET"])
def get_all_camera():
all_camera = Info.query.all()
result = info_schemas.dump(all_camera)
return jsonify(result.data)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) нет такой таблицы: info [SQL: 'SELECTinfo.id AS info_id, info. "camId" AS "info_camId", info.location AS info_location, info. "isActive" AS "info_isActive", info. "imgUrl" AS "info_imgUrl", info.gender AS info_gender, информация.age AS info_age \ nFROM info '] (Справочная информация об этой ошибке: http://sqlalche.me/e/e3q8)