[Flask] Read data from existing database

Ares Ou aresowj at gmail.com
Mon Dec 5 00:54:37 EST 2016


Hi Andreas,

You have to import Phrase1 from the file you define it.

For example:

from .models import Phrase1, Phrase2




Best regards,
Ares Ou

*Software Engineer / Full-Stack Python Developer*

*Blog:* http://aresou.net  |  *Github:* https://github.com/aresowj
*Stack Overflow:* http://stackoverflow.com/users/5183727/ares-ou

Ares Ou

On Sun, Dec 4, 2016 at 12:17 PM, Andreas Dorfner <
andreas.dorfner at stud.hs-regensburg.de> wrote:

> Hello everyone,
>
> I've created a data-logger using Flask-SQLAlchemy with the following
> schematic/models:
>
> class Phase1 with id, Urms, Irms, Prms, Qrms, cosphi
> class Phase2 with id, Urms, Irms, Prms, Qrms, cosphi
> class Phase3 with id, Urms, Irms, Prms, Qrms, cosphi
> class PhaseTotal with id, Prms, Qrms
>
> Attached you can find the resultant database created by the file
> logger_sqlalchemy.py.
>
> In the second part of the project I would like to set up a webserver to
> display the newest database-data on a website.
> Because there is an infinite loop in the logger file, another python file
> (webserver.py, also attached) is used to do so.
>
> Like described on the website "http://flask-sqlalchemy.
> pocoo.org/dev/queries/#querying-records"
> <http://flask-sqlalchemy.pocoo.org/dev/queries/#querying-records>, the
> following lines should display the Urms value with id 5 on the screen
> (logger_sqlalchemy.py doesn't run at this time):
>
> URMS_L1 = Phase1.query.filter_by(id=5).first()
> print(URMS_L1.Urms)
>
> But there is always an error "Phase1 is not defined"!
> Does anybody know what's going wrong?
>
> To link the file to the corresponding database, the following lines are
> used:
>
> app = Flask(__name__)
> app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////root/project/logger_sqlalchemy.db'
>
> db = SQLAlchemy(app)
>
> Maybe the link to the database is not correct? The database is in the same
> folder than the webserver file.
>
> Many thanks,
> Andreas
>
>
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient> Virenfrei.
> www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient>
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20161204/a3fe160c/attachment-0001.html>


More information about the Flask mailing list