ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Flask Hello

by tanrax ST2/ST3

Flask modern snippet for Sublime Text 3

Details

Installs

  • Total 445
  • Win 208
  • OS X 105
  • Linux 132
May 28 May 27 May 26 May 25 May 24 May 23 May 22 May 21 May 20 May 19 May 18 May 17 May 16 May 15 May 14 May 13 May 12 May 11 May 10 May 9 May 8 May 7 May 6 May 5 May 4 May 3 May 2 May 1 Apr 30 Apr 29 Apr 28 Apr 27 Apr 26 Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13
Windows 0 2 0 0 1 2 3 1 0 1 0 2 0 0 0 1 2 3 3 1 3 1 0 2 2 1 2 0 1 1 1 0 1 2 1 2 4 0 2 2 1 4 2 1 1 0
OS X 1 1 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 1 0 1 2 0 3 0 0 0 1 0 0 0 0 0 0 0 0 2 0 0 0 1 0 1 0 1 0 1
Linux 0 1 1 1 0 0 1 0 0 1 0 1 2 1 0 0 0 1 0 0 1 1 1 0 1 0 0 2 2 0 1 2 2 0 3 3 1 1 1 0 0 1 0 0 2 0

Readme

Source
raw.​githubusercontent.​com

Snippet Flask por Sublime Text

FlaskHello

Hello World

# -*- coding: utf-8 -*-
# Librarys
from flask import Flask, render_template

# Variables
app = Flask(__name__)

# Settings
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'secret'


# Views
@app.route('/', methods=('GET', 'POST'))
def index():
    return render_template('name.html')


# Run
if __name__ == '__main__':
    app.run()

FlaskModel

Snippet for Model with: Flask-sqlalchemy, Flask-script and flask-migrate.

# -*- coding: utf-8 -*-
# Librarys
from flask import Flask
from datetime import datetime
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

app = Flask(__name__)

# Settings
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# Variables
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)


class MyTable(db.Model):
    '''
    MyTable
    '''
    id = db.Column(db.Integer, primary_key=True)
    column_text = db.Column(db.String(128))
    column_int = db.Column(db.Integer)
    created_at = db.Column(
        db.DateTime, nullable=False, default=datetime.utcnow)
    updated_at = db.Column(
        db.DateTime, nullable=False, default=datetime.utcnow)
    category_id = db.Column(
        db.Integer, db.ForeignKey('category.id'), nullable=False)
    category = db.relationship(
        'Category', backref=db.backref('MyTable', lazy=True))

    def __repr__(self):
        return '<MyTable {0}>'.format(self.column_text)


if __name__ == "__main__":
    manager.run()

FlaskTFlash

Snippet Flash message for Template

{% with messages = get_flashed_messages() %}
    {% if messages %}
        {% for message in messages %}
            {{ message }}
        {% endfor %}
    {% endif %}
{% endwith %}

FlaskTFlashCategories

Snippet Flash message with categories for Template

{% with messages = get_flashed_messages(with_categories=true) %}
    {% if messages %}
        {% for category, message in messages %}
            <p class="{{ category }}">{{ message }}</p>
        {% endfor %}
    {% endif %}
{% endwith %}