本文整理匯總了Python中flaskext.sqlalchemy.SQLAlchemy.create_all方法的典型用法代碼示例。如果您正苦於以下問題:Python SQLAlchemy.create_all方法的具體用法?Python SQLAlchemy.create_all怎麽用?Python SQLAlchemy.create_all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flaskext.sqlalchemy.SQLAlchemy
的用法示例。
在下文中一共展示了SQLAlchemy.create_all方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from flaskext.sqlalchemy import SQLAlchemy [as 別名]
# 或者: from flaskext.sqlalchemy.SQLAlchemy import create_all [as 別名]
def main():
global app, db, web, database, pages
parser = OptionParser()
parser.add_option("-t", "--test-all", action="store_true", default=False, dest="test_all", help="Run all the tests.")
parser.add_option("-d", "--test-db", action="store_true", default=False, dest="test_db", help="Run the database tests.")
parser.add_option("-w", "--test-web", action="store_true", default=False, dest="test_web", help="Run the web tests.")
parser.add_option("-r", "--reset-db", action="store_true", default=False, dest="reset_db", help="Reset the database.")
parser.add_option("-s", "--script", metavar="SCRIPT", dest="script", default=None)
parser.add_option("--server", action="store_true", default=False, dest="start_server", help="Run the test webserver.")
(options, args) = parser.parse_args()
if options.test_all or options.test_db or options.test_web:
app = Flask(__name__.split('.')[0])
app.config['TESTING'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
db = SQLAlchemy(app)
suite = unittest.TestSuite()
if options.test_all or options.test_db:
import tests.database
suite.addTest(tests.database.suite)
if options.test_all or options.test_web:
import tests.web
suite.addTest(tests.web.suite)
unittest.TextTestRunner(verbosity=2).run(suite)
elif options.script is not None:
app = Flask(__name__.split('.')[0])
app.config.from_object(config.FlaskConfig)
db = SQLAlchemy(app)
import scripts
scripts = scripts.load_scripts()
if options.script in scripts:
scripts[options.script].main()
elif options.reset_db or options.start_server:
# Setup the application and database
app = Flask(__name__.split('.')[0])
app.config.from_object(config.FlaskConfig)
app.jinja_env.add_extension('jinja2.ext.do')
db = SQLAlchemy(app)
import database
import web
if options.reset_db:
db.drop_all()
db.create_all()
dataset.populate()
print 'Database reset.'
exit(0)
import pages
app.run(host='0.0.0.0', port=config.dev_port, use_reloader=True)
else:
parser.print_help()
示例2: Flask
# 需要導入模塊: from flaskext.sqlalchemy import SQLAlchemy [as 別名]
# 或者: from flaskext.sqlalchemy.SQLAlchemy import create_all [as 別名]
from flask import Flask
from flaskext.sqlalchemy import SQLAlchemy
from flaskext.uploads import configure_uploads, UploadSet, IMAGES
app = Flask(__name__)
# Load default configuration values, override with whatever is specified
# in configuration file. This is, I think, the sanest approach.
app.config.from_object('kremlin.config_defaults')
app.config.from_envvar('KREMLIN_CONFIGURATION')
# Set database from configuration values
app.config['SQLALCHEMY_DATABASE_URI'] = app.config['DATABASE_URI']
db = SQLAlchemy(app)
uploaded_images = UploadSet("images", IMAGES)
# Create upload set
# and configure like a motherfucker.
uploaded_images = UploadSet("images", IMAGES)
configure_uploads(app, uploaded_images)
# Import relevant modules
# this is done last to avoid touchy situations
import kremlin.dbmodel
import kremlin.core
import kremlin.forms
# Create all database tables
db.create_all()
示例3: reinit_db
# 需要導入模塊: from flaskext.sqlalchemy import SQLAlchemy [as 別名]
# 或者: from flaskext.sqlalchemy.SQLAlchemy import create_all [as 別名]
def reinit_db():
global db
db = SQLAlchemy(app)
db.create_all()
示例4: Transaction
# 需要導入模塊: from flaskext.sqlalchemy import SQLAlchemy [as 別名]
# 或者: from flaskext.sqlalchemy.SQLAlchemy import create_all [as 別名]
ABC-TRACK = Tracking ID
abc = UDF field 1
[email protected] = UDF field 2
hello = UDF field 3
Restrictions - none of your fields can include the / character
"""
# - Check if this order has already been paid
t = Transaction.query.filter_by(order_id=id, result='CAPTURED').first()
if t is not None:
return 'You have already paid for this order.'
# 2 - Build and dispatch KNET URL
trackid = trackingid or '{0.year}{0.month}{0.day}-{1}-{0.hour}{0.minute}{0.second}'.format(datetime.now(), id)
knet.parse()
if udf is not None:
udf = {'udf%s' % udf.find(x): x for x in udf if x is not ','}
payment_id, payment_url = knet.transaction(trackid, amount=total, udf=udf)
# Store information in DB
t = Transaction(trackid, id, total)
t.payment_id = payment_id
db.session.add(t)
db.session.commit()
return redirect(payment_url + '?PaymentID=' + payment_id)
if __name__ == '__main__':
db.create_all() # This will reset and recreate the database on each restart of the system
app.run(debug=True)