fix some bugs && change push way
This commit is contained in:
9
.gitignore
vendored
9
.gitignore
vendored
@@ -174,7 +174,10 @@ cython_debug/
|
|||||||
# PyPI configuration file
|
# PyPI configuration file
|
||||||
.pypirc
|
.pypirc
|
||||||
|
|
||||||
# 忽略媒体上传目录
|
# data/ directory for logs, static, media
|
||||||
*/media/*
|
data/logs/*
|
||||||
staticfiles/
|
data/media/*
|
||||||
|
data/static/*
|
||||||
|
!data/logs/.gitkeep
|
||||||
|
!data/media/.gitkeep
|
||||||
|
|
||||||
|
|||||||
24
AGENTS.md
24
AGENTS.md
@@ -7,14 +7,14 @@
|
|||||||
|
|
||||||
## Key commands
|
## Key commands
|
||||||
|
|
||||||
Run from `myblog/`:
|
Run from project root:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python manage.py runserver # dev server
|
python manage.py runserver # dev server
|
||||||
python manage.py makemigrations # after model changes
|
python manage.py makemigrations # after model changes
|
||||||
python manage.py migrate # apply migrations
|
python manage.py migrate # apply migrations
|
||||||
python manage.py createsuperuser # admin login
|
python manage.py createsuperuser # admin login
|
||||||
python manage.py collectstatic # prod: gather static files to staticfiles/
|
python manage.py collectstatic # prod: gather static files to data/static/
|
||||||
```
|
```
|
||||||
|
|
||||||
## Package management
|
## Package management
|
||||||
@@ -28,13 +28,17 @@ pip install -r requirements.txt # sync deps (no lockfile)
|
|||||||
## Project layout
|
## Project layout
|
||||||
|
|
||||||
```
|
```
|
||||||
myblog/
|
apps/ # 所有 Django 应用
|
||||||
├── blog/ # main app (models, views, templates, admin)
|
└── blog/ # 博客应用 (models, views, templates, admin)
|
||||||
│ └── static/blog/ # shared CSS (single style.css)
|
└── static/blog/ # 共享 CSS (style.css)
|
||||||
├── myblog/ # Django project settings/settings.py
|
config/ # Django 项目配置 (settings.py, urls.py, wsgi.py 等)
|
||||||
├── manage.py
|
manage.py
|
||||||
├── db.sqlite3 # dev DB (gitignored)
|
db.sqlite3 # dev DB (gitignored)
|
||||||
└── media/ # user uploads (gitignored)
|
|
||||||
|
data/ # 运行时数据
|
||||||
|
├── logs/ # Django logs (rotating, gitignored)
|
||||||
|
├── static/ # collectstatic output (gitignored)
|
||||||
|
└── media/ # user uploads (gitignored)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Key models
|
## Key models
|
||||||
@@ -47,7 +51,7 @@ Admin at `/admin/` with MDEditor on Post content field.
|
|||||||
|
|
||||||
## Local overrides
|
## Local overrides
|
||||||
|
|
||||||
Create `myblog/myblog/local_settings.py` to override any setting. Imported at the bottom of `settings.py`.
|
Create `config/local_settings.py` to override any setting. Imported at the bottom of `settings.py`.
|
||||||
|
|
||||||
## Git workflow
|
## Git workflow
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ class PostAdmin(admin.ModelAdmin):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 设置列表显示字段
|
# 设置列表显示字段
|
||||||
list_display = ('title', 'publish_date', 'created_at', 'updated_at')
|
list_display = ('title', 'category', 'status', 'publish_date', 'created_at', 'updated_at')
|
||||||
|
# 设置过滤器
|
||||||
|
list_filter = ('status', 'category', 'publish_date')
|
||||||
# 设置搜索字段
|
# 设置搜索字段
|
||||||
search_fields = ('title', 'content')
|
search_fields = ('title', 'content')
|
||||||
|
|
||||||
18
apps/blog/migrations/0011_alter_post_status.py
Normal file
18
apps/blog/migrations/0011_alter_post_status.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.1 on 2026-08-25 10:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('blog', '0010_post_status'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='post',
|
||||||
|
name='status',
|
||||||
|
field=models.CharField(choices=[('draft', '草稿'), ('published', '已发布')], default='published', max_length=10),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
import re
|
||||||
|
import emoji
|
||||||
import markdown
|
import markdown
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from mdeditor.fields import MDTextField
|
from mdeditor.fields import MDTextField
|
||||||
@@ -52,14 +54,12 @@ class Post(models.Model):
|
|||||||
# 添加分类字段,建立外键关系
|
# 添加分类字段,建立外键关系
|
||||||
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True, related_name='posts')
|
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, blank=True, related_name='posts')
|
||||||
# 添加状态字段
|
# 添加状态字段
|
||||||
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default=DRAFT)
|
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default=PUBLISHED)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.title}"
|
return f"{self.title}"
|
||||||
|
|
||||||
def get_markdown_content(self):
|
def get_markdown_content(self):
|
||||||
import re
|
|
||||||
import emoji
|
|
||||||
content = self.content
|
content = self.content
|
||||||
media_url = settings.MEDIA_URL.rstrip('/')
|
media_url = settings.MEDIA_URL.rstrip('/')
|
||||||
|
|
||||||
0
config/__init__.py
Normal file
0
config/__init__.py
Normal file
@@ -8,8 +8,11 @@ https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myblog.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||||
|
# 将 apps/ 加入 Python 路径
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'apps'))
|
||||||
|
|
||||||
application = get_asgi_application()
|
application = get_asgi_application()
|
||||||
25
config/local_settings.example.py
Normal file
25
config/local_settings.example.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
"""
|
||||||
|
本地设置示例文件
|
||||||
|
使用方法:复制为 local_settings.py 并按需修改
|
||||||
|
cp local_settings.example.py local_settings.py
|
||||||
|
"""
|
||||||
|
|
||||||
|
# 生产环境请设置
|
||||||
|
# import os
|
||||||
|
# SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'your-secret-key')
|
||||||
|
|
||||||
|
# DEBUG = False
|
||||||
|
|
||||||
|
# ALLOWED_HOSTS = ['www.yuangyaa.com', 'yuangyaa.com']
|
||||||
|
|
||||||
|
# 生产环境数据库(PostgreSQL)
|
||||||
|
# DATABASES = {
|
||||||
|
# 'default': {
|
||||||
|
# 'ENGINE': 'django.db.backends.postgresql',
|
||||||
|
# 'NAME': 'blog',
|
||||||
|
# 'USER': 'blog_user',
|
||||||
|
# 'PASSWORD': 'your_password',
|
||||||
|
# 'HOST': 'localhost',
|
||||||
|
# 'PORT': '5432',
|
||||||
|
# }
|
||||||
|
# }
|
||||||
@@ -11,16 +11,20 @@ https://docs.djangoproject.com/en/5.2/ref/settings/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
DATA_DIR = BASE_DIR.parent / 'data'
|
DATA_DIR = BASE_DIR / 'data'
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = 'django-insecure-g224%sp()h))26kj26pnnfoayu-knah+!)h9uzgqeece&6*clp'
|
SECRET_KEY = os.environ.get(
|
||||||
|
'DJANGO_SECRET_KEY',
|
||||||
|
'django-insecure-g224%sp()h))26kj26pnnfoayu-knah+!)h9uzgqeece&6*clp'
|
||||||
|
)
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
@@ -50,7 +54,7 @@ MIDDLEWARE = [
|
|||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'myblog.urls'
|
ROOT_URLCONF = 'config.urls'
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
@@ -67,7 +71,7 @@ TEMPLATES = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'myblog.wsgi.application'
|
WSGI_APPLICATION = 'config.wsgi.application'
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
||||||
@@ -8,8 +8,11 @@ https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myblog.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||||
|
# 将 apps/ 加入 Python 路径
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'apps'))
|
||||||
|
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
0
data/logs/.gitkeep
Normal file
0
data/logs/.gitkeep
Normal file
0
data/media/.gitkeep
Normal file
0
data/media/.gitkeep
Normal file
0
identifier.sqlite
Normal file
0
identifier.sqlite
Normal file
@@ -6,7 +6,9 @@ import sys
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Run administrative tasks."""
|
"""Run administrative tasks."""
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myblog.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||||
|
# 将 apps/ 加入 Python 路径,使 Django 能找到各应用
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'apps'))
|
||||||
try:
|
try:
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
@@ -16,11 +16,8 @@ ipython==9.4.0
|
|||||||
ipython_pygments_lexers==1.1.1
|
ipython_pygments_lexers==1.1.1
|
||||||
jedi==0.19.2
|
jedi==0.19.2
|
||||||
Markdown==3.5.2
|
Markdown==3.5.2
|
||||||
martor==1.6.45
|
|
||||||
matplotlib-inline==0.1.7
|
matplotlib-inline==0.1.7
|
||||||
numpy==2.3.2
|
|
||||||
packaging==25.0
|
packaging==25.0
|
||||||
pandas==2.3.1
|
|
||||||
parso==0.8.4
|
parso==0.8.4
|
||||||
pexpect==4.9.0
|
pexpect==4.9.0
|
||||||
pillow==11.3.0
|
pillow==11.3.0
|
||||||
@@ -38,7 +35,6 @@ stack-data==0.6.3
|
|||||||
traitlets==5.14.3
|
traitlets==5.14.3
|
||||||
tzdata==2025.2
|
tzdata==2025.2
|
||||||
urllib3==2.5.0
|
urllib3==2.5.0
|
||||||
uv==0.8.3
|
|
||||||
uvicorn==0.35.0
|
uvicorn==0.35.0
|
||||||
wcwidth==0.2.13
|
wcwidth==0.2.13
|
||||||
webencodings==0.5.1
|
webencodings==0.5.1
|
||||||
|
|||||||
Reference in New Issue
Block a user