Initial commit

This commit is contained in:
2025-11-18 03:36:49 +08:00
commit d17c7efb3c
7078 changed files with 831480 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
import pymysql
pymysql.install_as_MySQLdb()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

16
pygoedge_panel/asgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
ASGI config for pygoedge_panel project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pygoedge_panel.settings')
application = get_asgi_application()

View File

@@ -0,0 +1,8 @@
"""环境入口:根据 DJANGO_ENV 选择 dev 或 prod 配置。默认 dev。"""
import os
env = os.getenv('DJANGO_ENV', 'dev').lower()
if env == 'prod':
from .settings.prod import * # noqa
else:
from .settings.dev import * # noqa

View File

@@ -0,0 +1,8 @@
"""环境入口:根据 DJANGO_ENV 选择 dev 或 prod 配置。默认 dev。"""
import os
env = os.getenv('DJANGO_ENV', 'dev').lower()
if env == 'prod':
from .prod import * # noqa
else:
from .dev import * # noqa

View File

@@ -0,0 +1,131 @@
from pathlib import Path
import os
import logging
from dotenv import load_dotenv
# Base paths
BASE_DIR = Path(__file__).resolve().parent.parent.parent
load_dotenv(os.path.join(BASE_DIR, ".env"))
# Core settings
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', 'django-insecure-change-me')
# DEBUG/ALLOWED_HOSTS 在 dev/prod 中覆盖
DEBUG = False
ALLOWED_HOSTS = [h for h in os.getenv('DJANGO_ALLOWED_HOSTS', '*').split(',') if h]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# project apps
'core',
'accounts',
'domains',
'plans',
'billing',
'admin_panel',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'pygoedge_panel.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'pygoedge_panel.wsgi.application'
# Database (env-driven)
DB_ENGINE = os.getenv('DB_ENGINE', 'sqlite').lower()
if DB_ENGINE == 'mysql':
try:
import pymysql # type: ignore
pymysql.install_as_MySQLdb()
except Exception as e:
logging.getLogger(__name__).exception('pymysql install as MySQLdb failed')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.getenv('DB_NAME', 'pygoedge'),
'USER': os.getenv('DB_USER', 'root'),
'PASSWORD': os.getenv('DB_PASSWORD', ''),
'HOST': os.getenv('DB_HOST', '127.0.0.1'),
'PORT': os.getenv('DB_PORT', '3306'),
'OPTIONS': {
'charset': 'utf8mb4',
}
}
}
# 连接复用(生产建议开启)
CONN_MAX_AGE = int(os.getenv('DB_CONN_MAX_AGE', '60'))
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# i18n
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_TZ = True
# Static
STATIC_URL = 'static/'
STATICFILES_DIRS = [BASE_DIR / 'static']
# Auth
LOGIN_URL = '/admin/login/'
LOGIN_REDIRECT_URL = '/domains/'
# CSRF trusted origins (optional)
CSRF_TRUSTED_ORIGINS = [o for o in os.getenv('DJANGO_CSRF_TRUSTED_ORIGINS', '').split(',') if o]
# Default PK
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

View File

@@ -0,0 +1,7 @@
from .base import * # noqa
import os
DEBUG = True
# 开发环境允许任意主机访问,或从环境覆盖
ALLOWED_HOSTS = [h for h in os.getenv('DJANGO_ALLOWED_HOSTS', '*').split(',') if h]

View File

@@ -0,0 +1,19 @@
from .base import * # noqa
import os
# 生产环境强制关闭调试
DEBUG = False
# 明确设置允许的主机名
ALLOWED_HOSTS = [h for h in os.getenv('DJANGO_ALLOWED_HOSTS', '').split(',') if h] or ['localhost']
# 安全相关(按需开启)
SECURE_SSL_REDIRECT = os.getenv('DJANGO_SECURE_SSL_REDIRECT', 'False').lower() == 'true'
SESSION_COOKIE_SECURE = os.getenv('DJANGO_SESSION_COOKIE_SECURE', 'True').lower() == 'true'
CSRF_COOKIE_SECURE = os.getenv('DJANGO_CSRF_COOKIE_SECURE', 'True').lower() == 'true'
# CSRF 信任域(如 https://panel.example.com
CSRF_TRUSTED_ORIGINS = [o for o in os.getenv('DJANGO_CSRF_TRUSTED_ORIGINS', '').split(',') if o]
# 生产环境静态文件收集目录(用于 collectstatic
STATIC_ROOT = BASE_DIR / 'staticfiles'

27
pygoedge_panel/urls.py Normal file
View File

@@ -0,0 +1,27 @@
"""
URL configuration for pygoedge_panel project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include(('accounts.urls', 'accounts'), namespace='accounts')),
path('domains/', include(('domains.urls', 'domains'), namespace='domains')),
path('plans/', include(('plans.urls', 'plans'), namespace='plans')),
path('billing/', include(('billing.urls', 'billing'), namespace='billing')),
path('admin-panel/', include(('admin_panel.urls', 'admin_panel'), namespace='admin_panel')),
]

16
pygoedge_panel/wsgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
WSGI config for pygoedge_panel project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pygoedge_panel.settings')
application = get_wsgi_application()