Skip to content

Instantly share code, notes, and snippets.

@tai271828
Last active November 6, 2020 20:34
Show Gist options
  • Save tai271828/91b189936225326cd5a79f8a87bd179d to your computer and use it in GitHub Desktop.
Save tai271828/91b189936225326cd5a79f8a87bd179d to your computer and use it in GitHub Desktop.
flask-cookbook - code snippet collection of flask examples

flask-cookbook - code snippet collection of flask examples

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!'
[[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