hequan2017 c18367f856 fix: 修复 246 个 Dependabot 依赖漏洞
- requirements.txt 由 2019 年 pip freeze 快照重写为直接依赖清单(Python>=3.10)
- Django 2.2.4 -> 5.2.16,DRF 3.9.2 -> 3.17.2,channels 2.2 -> 4.3,celery 4.1 -> 5.5
- 移除代码未使用的 apache-airflow/tornado/GitPython/numpy/thrift/lxml/SQLAlchemy/Mako/Werkzeug/gevent/autobahn/ipython 等历史依赖(含 system/tests.py 中的 airflow 示例)
- 已停维的 django-rest-swagger/DRF coreapi 文档替换为 drf-spectacular
- celery.platforms/C_FORCE_ROOT/CELERYBEAT_SCHEDULE 按 celery 5 规范迁移
- asgi.py 迁移至 channels 4 入口写法;graphene-django 升级至 3.x(schema 增加 fields)
- static/js/jquery-3.1.1.min.js(XSS 漏洞)替换为 jquery-3.7.1 并更新模板引用
2026-09-28 14:12:54 +08:00
2019-06-13 15:50:13 +08:00
2019-07-09 17:39:08 +08:00
2019-08-28 15:51:39 +08:00
2019-08-06 15:11:13 +08:00
2019-06-21 17:26:19 +08:00
2019-07-09 17:39:08 +08:00
2019-03-02 12:06:22 +08:00
2019-03-02 12:02:55 +08:00
2019-03-01 23:48:18 +08:00
2019-03-02 12:02:55 +08:00

简体中文 | English

Seal (海豹)

django-base-templates — a Django development DEMO platform, supporting both non-separated (server-rendered) and separated (front-end / back-end) modes

Version Language Env Bootstrap3 RESTful GraphQL

The project started on March 1st, which is International Seal Day, hence the name "Seal" (海豹).

Introduction

Seal is a Django base development platform template built with the MVC pattern. It supports both non-separated development (Django template rendering) and separated development (RESTful / GraphQL APIs), so you can use it as a reference when building your own Django projects.

It is based on Django 2.2 + Python 3.6 + Celery 4 for async tasks, uses the Inspinia 2.7 front-end template (Bootstrap3), and is developed entirely with CBVs (Class-Based Views). It also ships with DRF RESTful API examples, GraphQL examples, Kubernetes management, and SQL audit/execution modules as real-world references.

Beyond being a base template, the project includes two complete ops-oriented implementations: a K8s web console (Node / Service / Pod lists + Pod WebSSH, executing commands via the Kubernetes API) and a SQL audit & execution engine (goInception / soar).

The author develops and updates this project on weekends.

✨ Features

  • Base development templates: base web layout template + system platform pages (home / login / password change), front-end template Inspinia 2.7 (Bootstrap3)
  • Asset management example: the assets app provides a complete CRUD (CBV) example to reference when developing your own modules
  • RESTful API: DRF-based API examples with Token authentication (/api/token), plus two built-in API docs endpoints (/api/docs/ and Swagger-style /api/docs2/)
  • GraphQL: graphene-django Query / Mutation examples (user list, single query, create/update/delete) with a built-in GraphiQL playground (/graphql/)
  • Kubernetes management: Node / Service / Pod lists and Pod details, plus Pod WebSSH (django-channels + WebSocket, executing commands inside Pods via the Kubernetes API)
  • SQL audit & execution: goInception for SQL checking / execution (with backup support) and soar for SQL optimization advice; supports multiple database environments
  • Two async task options: Celery (recommended for scheduled tasks, with django-celery-beat / django-celery-results / flower) and dramatiq (ordinary async tasks)
  • Permission control: login authentication + Django Permission-based page-level checks; the Django admin is prettified with django-simpleui

Roadmap

  • Phase 1: base templates (done)
  • Phase 2: Kubernetes management platform (in progress)
    • node/service/pod lists (done)
    • pod webssh (done, executing commands via the Kubernetes API)
  • Phase 3: MySQL SQL statement audit (done)
    • SQL check and execution
  • Phase 4: in progress — rebuilding the front end https://github.com/hequan2017/seal-d2-admin

🛠 Tech Stack

Backend

  • Python 3.6 / Django 2.2.4 (CBV style)
  • Django REST framework 3.9.2 + django-rest-swagger (API and docs)
  • graphene-django 2.2.0 (GraphQL)
  • celery 4.1.1 + django-celery-beat + django-celery-results + flower; dramatiq 1.5.0 (async tasks)
  • django-channels 2.2.0 + channels-redis (WebSocket channel for Pod WebSSH)
  • kubernetes 9.0.0 (official Kubernetes Python client), PyMySQL / mysqlclient, paramiko, psutil

Front-end

Storage & services

  • MySQL 5.7 / SQLite
  • Redis (broker and backend for celery / dramatiq / channels)

SQL audit tools

  • goInception / soar (executables are bundled in the repo under sql/bin/)

🚀 Quick Start

Requirements: Python 3.6, MySQL 5.7 (or SQLite), Redis.

yum install python-devel mysql-devel python36-devel.x86_64 -y

git clone https://github.com/hequan2017/seal
cd seal

## Django 2.2 does not support older versions of SQLite. If you want to use
## SQLite for storage, please upgrade it following this blog post:
## https://www.jianshu.com/p/cdacf4b74646

python36 -m pip install -r requirements.txt
python36 manage.py makemigrations
python36 manage.py migrate
python36 manage.py createsuperuser

python36 manage.py runserver 0.0.0.0:8001

// Run in the background
// nohup python36 manage.py runserver 0.0.0.0:8001 >> /tmp/http.log 2>&1 &

K8s Module

Edit the K8s settings in seal/settings.py (see k8s/k8sApi/获取k8s admin token的方法.md for how to get the admin token):

## K8S
Token = "<dashboard-admin-token>"
APISERVER = 'https://192.168.100.111:6443'

SQL Module

Enter the project directory cd seal. The backup server can be configured in sql/bin/config/config.toml; for details, search for goInception on GitHub:

chmod +x sql/bin/soar
chmod +x sql/bin/goInception

./sql/bin/goInception -config=sql/bin/config/config.toml

Async Tasks

  • Async option 1: Celery is recommended for scheduled tasks
cd seal
celery -B -A seal worker -l info
  • Async option 2: dramatiq for ordinary async tasks
cd system/decorator/asynchronous/
dramatiq asynchronous --watch . --log-file /tmp/dramatiq.log

Notes

  • If you plan to use this in production, regenerate the SECRET_KEY in the settings file.
  • Timezone: timezone support is enabled, so Django stores UTC times in the database and converts them to UTC+8 when you read them through the timezone API; Celery recognizes the timezone automatically.
from django.utils import timezone
for i in Users.objects.all():
    print(i.last_login)  ## Reading the field directly returns a UTC time; handle it carefully if needed
    print(timezone.localtime(i.last_login).strftime("%Y-%m-%d %H:%M:%S"))  ## Format into local time

## 2019-03-05 06:41:18.040809+00:00
## 2019-03-05 14:41:18

📁 Directory Structure

seal/
├── assets/      # Asset management (CRUD example)
├── k8s/         # Kubernetes management (node/service/pod lists, pod detail, webssh)
├── sql/         # SQL audit & execution (goInception / soar; executables in bin/)
├── system/      # System module (login / users / password / async task examples)
├── document/    # Demo screenshots, SQL notes, coding standards
├── templates/   # Page templates (base/system/assets/k8s/sql)
├── static/      # Static assets (inspinia, ace, echarts, ueditor, etc.)
└── seal/        # Project configuration (settings / urls / schema / routing / celery)

📸 DEMO / Screenshots

Demo: http://129.28.156.219:8001

Account: admin Password: 1qaz.2wsx

API docs: http://129.28.156.219:8001/api/docs/

List Create API API API K8S K8S SQL

GraphQL Examples

See seal/schema.py for the code. Endpoint: http://localhost/graphql

GraphQL request examples:

query{
  users{
    id,
    username,
    email
  }
}

query{
  singleUser(pk: 1){
    username,
    email
  }
}

mutation createUser {
 createUser (username: "test1") {
     info {
         id,
     },
     ok
 }
}

mutation updateUser {
 updateUser (pk:2,username: "test2") {
     info {
         id,
     },
     ok
 }
}

mutation deleteUser {
 deleteUser (pk:2) {
     ok
 }
}

📄 License

MIT © 2019 He Quan (何全)

Support / Resources

Community

  • For questions, join the QQ group: 620176501 django开发讨论群
  • Feature requests, feedback, and contributions are welcome.

Author

  • 何全 (He Quan)
Languages
Python 99.8%
Less 0.1%
PHP 0.1%