完成wordpress到django站点的数据迁移,下一届阶段完成前端样式的轻度编写

This commit is contained in:
2026-10-20 02:55:22 +08:00
parent 9592e6a150
commit 16a75807ee
30 changed files with 27989 additions and 51 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
+39 -4
View File
@@ -55,7 +55,7 @@ ROOT_URLCONF = "blogsite.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
'DIRS': [BASE_DIR / 'blog' / 'templates'], # 模板目录
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
@@ -73,10 +73,45 @@ WSGI_APPLICATION = "blogsite.wsgi.application"
# Database
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
# DATABASES = {
# "default": {
# "ENGINE": "django.db.backends.sqlite3",
# "NAME": BASE_DIR / "db.sqlite3",
# }
# }
"""
数据库配置
原来默认是 SQLite:
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
现在换成 MySQL
"""
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
'default': {
# 数据库引擎,指定为 MySQL
'ENGINE': 'django.db.backends.mysql',
# 数据库名(刚才 CREATE DATABASE 的那个名字)
'NAME': 'blog_db',
# MySQL 用户名
'USER': 'root',
# MySQL 密码
'PASSWORD': 'guoan123', # ← 改成你自己的 MySQL 密码
# MySQL 地址
'HOST': '127.0.0.1', # 本地就是 127.0.0.1,远程就填 IP
# MySQL 端口(默认 3306)
'PORT': '3306',
# 额外选项
'OPTIONS': {
# 自动提交事务
'autocommit': True,
# 设置连接字符集
'charset': 'utf8mb4',
# SQL 模式:严格模式,避免静默截断数据
'sql_mode': 'STRICT_TRANS_TABLES',
},
}
}
+24 -2
View File
@@ -15,9 +15,31 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
"""
项目根路由
所有请求先到这里,再分发到各个 app 的 urls.py
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path("admin/", admin.site.urls),
# 管理后台
path('admin/', admin.site.urls),
# 博客 app 的所有路由
# 空字符串表示挂载到根路径
# 比如 blog/urls.py 里定义了 '' → 实际访问 /
path('', include('blog.urls')),
]
# 开发环境下,让 Django 提供 media 文件的访问
# 生产环境应该用 Nginx/Apache 直接提供静态文件
if settings.DEBUG:
urlpatterns += static(
settings.MEDIA_URL, # URL 前缀 /media/
document_root=settings.MEDIA_ROOT # 实际文件路径
)