https://github.com/tanrax/sublimeflaskhello
Flask modern snippet for Sublime Text 3
https://github.com/tanrax/sublimeflaskhello
Last synced: 10 months ago
JSON representation
Flask modern snippet for Sublime Text 3
- Host: GitHub
- URL: https://github.com/tanrax/sublimeflaskhello
- Owner: tanrax
- Created: 2017-10-13T12:05:36.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-17T20:26:19.000Z (about 8 years ago)
- Last Synced: 2025-01-14T05:50:47.840Z (12 months ago)
- Size: 20.5 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Snippet Flask por Sublime Text
## FlaskHello
Hello World
```python
# -*- 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.
```python
# -*- 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 ''.format(self.column_text)
if __name__ == "__main__":
manager.run()
```
## FlaskTFlash
Snippet Flash message for Template
```jinja
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
{{ message }}
{% endfor %}
{% endif %}
{% endwith %}
```
## FlaskTFlashCategories
Snippet Flash message with categories for Template
```jinja
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
{{ message }}
{% endfor %}
{% endif %}
{% endwith %}
```