flask-cookbook - code snippet collection of flask examples
Last active
November 6, 2020 20:34
-
-
Save tai271828/91b189936225326cd5a79f8a87bd179d to your computer and use it in GitHub Desktop.
flask-cookbook - code snippet collection of flask examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask_sqlalchemy import SQLAlchemy | |
app = Flask(__name__) | |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test-hello.db' | |
db = SQLAlchemy(app) | |
class User(db.Model): | |
id = db.Column(db.Integer, primary_key=True) | |
username = db.Column(db.String(80), unique=True, nullable=False) | |
email = db.Column(db.String(120), unique=True, nullable=False) | |
def __repr__(self): | |
return '<User %r>' % self.username | |
@app.route('/') | |
def hello_world(): | |
db.create_all() | |
admin = User(username='admin', email='[email protected]') | |
guest = User(username='guest', email='[email protected]') | |
db.session.add(admin) | |
db.session.add(guest) | |
db.session.commit() | |
return 'Hello, World!' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[source]] | |
name = "pypi" | |
url = "https://pypi.org/simple" | |
verify_ssl = true | |
[dev-packages] | |
[packages] | |
[requires] | |
python_version = "3.7" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment