|
|
|
|
@ -47,32 +47,48 @@ DjangoBlog is a high-performance blog platform built with Python 3.10 and Django
|
|
|
|
|
Ensure you have Python 3.10+ and MySQL/MariaDB installed on your system.
|
|
|
|
|
|
|
|
|
|
### 2. Clone & Installation
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# Clone the project to your local machine
|
|
|
|
|
```
|
|
|
|
|
# 将项目克隆到本地机器
|
|
|
|
|
git clone https://github.com/liangliangyy/DjangoBlog.git
|
|
|
|
|
|
|
|
|
|
# 进入项目目录(切换到DjangoBlog文件夹)
|
|
|
|
|
cd DjangoBlog
|
|
|
|
|
|
|
|
|
|
# Install dependencies
|
|
|
|
|
# 安装项目所需的依赖包
|
|
|
|
|
pip install -r requirements.txt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 3. Project Configuration
|
|
|
|
|
|
|
|
|
|
- **Database**:
|
|
|
|
|
Open `djangoblog/settings.py`, locate the `DATABASES` section, and update it with your MySQL connection details.
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
DATABASES = {
|
|
|
|
|
'default': {
|
|
|
|
|
'ENGINE': 'django.db.backends.mysql',
|
|
|
|
|
'NAME': 'djangoblog',
|
|
|
|
|
'USER': 'root',
|
|
|
|
|
'PASSWORD': 'your_password',
|
|
|
|
|
'HOST': '127.0.0.1',
|
|
|
|
|
'PORT': 3306,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# 数据库配置字典,Django通过此配置连接数据库
|
|
|
|
|
DATABASES = {
|
|
|
|
|
# 默认数据库配置
|
|
|
|
|
'default': {
|
|
|
|
|
# 数据库引擎,这里使用MySQL数据库后端
|
|
|
|
|
# 'django.db.backends.mysql'表示使用MySQL数据库
|
|
|
|
|
# 其他可选值包括sqlite3、postgresql、oracle等
|
|
|
|
|
'ENGINE': 'django.db.backends.mysql',
|
|
|
|
|
|
|
|
|
|
# 数据库名称,需要提前在MySQL中创建该数据库
|
|
|
|
|
'NAME': 'djangoblog',
|
|
|
|
|
|
|
|
|
|
# 数据库登录用户名
|
|
|
|
|
'USER': 'root',
|
|
|
|
|
|
|
|
|
|
# 数据库登录密码,需要替换为你的实际密码
|
|
|
|
|
'PASSWORD': 'your_password',
|
|
|
|
|
|
|
|
|
|
# 数据库主机地址,127.0.0.1表示本地数据库
|
|
|
|
|
# 若数据库在远程服务器,可改为对应IP地址或域名
|
|
|
|
|
'HOST': '127.0.0.1',
|
|
|
|
|
|
|
|
|
|
# 数据库端口,MySQL默认端口为3306
|
|
|
|
|
'PORT': 3306,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
Create the database in MySQL:
|
|
|
|
|
```sql
|
|
|
|
|
@ -82,27 +98,38 @@ pip install -r requirements.txt
|
|
|
|
|
- **More Configurations**:
|
|
|
|
|
For advanced settings such as email, OAuth, caching, and more, please refer to our [Detailed Configuration Guide](/docs/config-en.md).
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
### 4. Database Initialization
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# 生成数据库迁移文件
|
|
|
|
|
# 根据模型的变更创建迁移脚本,记录数据模型的修改
|
|
|
|
|
python manage.py makemigrations
|
|
|
|
|
|
|
|
|
|
# 执行数据库迁移
|
|
|
|
|
# 将迁移文件中定义的变更应用到实际数据库中,创建或修改表结构
|
|
|
|
|
python manage.py migrate
|
|
|
|
|
|
|
|
|
|
# Create a superuser account
|
|
|
|
|
# Create a superuser account 创建超级用户账号
|
|
|
|
|
# 生成可以登录Django管理后台的超级用户(管理员),用于管理网站内容
|
|
|
|
|
python manage.py createsuperuser
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 5. Running the Project
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
# (Optional) Generate some test data
|
|
|
|
|
```
|
|
|
|
|
# (可选)生成一些测试数据
|
|
|
|
|
# 为项目创建示例数据(如测试文章、用户等),方便开发和测试时查看效果
|
|
|
|
|
python manage.py create_testdata
|
|
|
|
|
|
|
|
|
|
# (Optional) Collect and compress static files
|
|
|
|
|
# (可选)收集并压缩静态文件
|
|
|
|
|
# 收集项目中所有静态文件(CSS、JS、图片等)到指定目录,--noinput参数表示无需手动确认
|
|
|
|
|
python manage.py collectstatic --noinput
|
|
|
|
|
|
|
|
|
|
# 压缩静态文件(如CSS、JS)以减小文件体积,提高加载速度,--force参数强制覆盖已有文件
|
|
|
|
|
python manage.py compress --force
|
|
|
|
|
|
|
|
|
|
# Start the development server
|
|
|
|
|
# 启动开发服务器
|
|
|
|
|
# 启动Django内置的开发用Web服务器,默认地址为http://127.0.0.1:8000/
|
|
|
|
|
# 开发过程中修改代码后服务器会自动重启,方便调试
|
|
|
|
|
python manage.py runserver
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|