Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

flask

БесплатноБез исполняемых скриптовНе проверен

Flask is a lightweight Python web framework built on Werkzeug and Jinja2; it gives you routing, requests, templates and a test client and leaves the rest to…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Flask

Overview

Flask is a micro web framework for Python. It is minimal by design: you pick the ORM, auth and layout, and extensions fill the gaps. This skill covers Flask 3.1 (3.1.3, February 2026; it needs Python 3.9 or newer) with Flask-SQLAlchemy 3.1, Flask-Migrate 4.1 and Flask-Login 0.6, using the application-factory plus blueprints layout. The code below was run with those versions: tests pass and the migrations apply.

Instructions

Install

python3 -m venv .venv
.venv/bin/pip install flask flask-sqlalchemy flask-migrate flask-login pytest gunicorn

Extensions and configuration

The project is a package app/ with config.py, extensions.py, models.py, blueprint packages main/ and api/, templates/, and tests/ beside it.

Create extensions in their own module, without an app, so blueprints import them without circular imports. Pass a DeclarativeBase subclass as model_class for SQLAlchemy 2.0 style models.

# app/extensions.py
from flask_login import LoginManager
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase

class Base(DeclarativeBase):
    pass

db = SQLAlchemy(model_class=Base)
migrate = Migrate()
login_manager = LoginManager()
login_manager.login_view = "main.login"
# app/config.py
import os

class Config:
    SECRET_KEY = os.environ["SECRET_KEY"]  # fail at startup if it is missing
    SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL", "sqlite:///app.db")

class TestConfig(Config):
    TESTING = True
    SECRET_KEY = "test-only-secret"
    SQLALCHEMY_DATABASE_URI = "sqlite://"

SECRET_KEY signs the session cookie. Read it from the environment without a default, so a forgotten variable stops the app at startup instead of shipping a guessable key.

Application factory

# app/__init__.py
from flask import Flask

from .config import Config
from .extensions import db, login_manager, migrate

def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(config_class)

    db.init_app(app)
    migrate.init_app(app, db)
    login_manager.init_app(app)

    from .api import bp as api_bp
    from .main import bp as main_bp

    app.register_blueprint(main_bp)
    app.register_blueprint(api_bp, url_prefix="/api")

    return app

Models

# app/models.py
from datetime import datetime, timezone

from flask_login import UserMixin
from sqlalchemy import ForeignKey, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship
from werkzeug.security import check_password_hash, generate_password_hash

from .extensions import db, login_manager

class User(UserMixin, db.Model):
    id: Mapped[int] = mapped_column(primary_key=True)
    username: Mapped[str] = mapped_column(String(80), unique=True)
    password_hash: Mapped[str] = mapped_column(String(256))
    posts: Mapped[list["Post"]] = relationship(back_populates="author")

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

class Post(db.Model):
    id: Mapped[int] = mapped_column(primary_key=True)
    body: Mapped[str] = mapped_column(Text)
    created_at: Mapped[datetime] = mapped_column(default=lambda: datetime.now(timezone.utc))
    user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))
    author: Mapped[User] = relationship(back_populates="posts")

@login_manager.user_loader
def load_user(user_id):
    return db.session.get(User, int(user_id))

HTML blueprint

Each blueprint package's __init__.py creates bp = Blueprint("main", __name__) and then imports its routes module at the bottom (from . import routes); the api package does the same with Blueprint("api", __name__).

# app/main/routes.py
from flask import flash, redirect, render_template, request, url_for
from flask_login import login_user

from ..extensions import db
from ..models import Post, User
from . import bp

@bp.route("/")
def index():
    page = request.args.get("page", 1, type=int)
    query = db.select(Post).order_by(Post.created_at.desc())
    posts = db.paginate(query, page=page, per_page=20, error_out=False)
    return render_template("main/index.html", posts=posts)

@bp.route("/login", methods=["GET", "POST"])
def login():
    if request.method == "POST":
        user = db.session.scalar(
            db.select(User).where(User.username == request.form["username"])
        )
        if user and user.check_password(request.form["password"]):
            login_user(user)
            return redirect(url_for("main.index"))
        flash("Wrong username or password")
    return render_template("main/login.html")

db.paginate() takes a select() and returns a pagination object that you can loop over in the template (posts.items, posts.has_next, posts.next_num). The ol

Полный SKILL.md на GitHub

Установить flask в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл flask?

Flask is a lightweight Python web framework built on Werkzeug and Jinja2; it gives you routing, requests, templates and a test client and leaves the rest to extensions. Use this skill when the user wants to build a Flask app or JSON API, set up an application factory with blueprints, add Flask-SQLAlchemy, Flask-Migrate or Flask-Login, write pytest tests for a Flask app, or run it with the flask CLI and gunicorn.

Как установить скилл flask?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл flask запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить flask с