The callback can take app and/or db args, or the function signature can be left blank: from flask_postgres import init_db_callback def init_db ( app, db ): db. Check that the commands are available here: flask psql -helpįlask-Postgres does not require any more setup than this, unless you want to add a custom callback that runs when psql init is executed. Once you have installed Flask-Postgres, you should be ready to go assuming your code is already set up to use Flask-SQLAlchemy. Want to make a change, and don't mind starting everything over? Then run: flask psql reset Now run in your terminal: flask psql setupĪnd you'll have a Postgres database up and running with the initialized data. create_all () # Add your first pet pet = Pet ( name = "Fido" ) db. Integer, primary_key = True, autoincrement = True ) name = db. config = False db = SQLAlchemy ( app ) class Pet ( db. config = "postgresql://localhost:5432/example" app. # app.py from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_postgres import init_db_callback app = Flask ( _name_ ) app. The below example shows an app with a custom init_db_callback, which is optional.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |