DjangoBlog project address:
https://github.com/liangliangyy/DjangoBlog
1.First install the git tool to clone the DjangoBlog project:
RedHat|CentOS:
yum install git -y
Debian|Ubuntu:
apt-get update
apt-get install git -y
Clone the DjangoBlog project:
cd /www/wwwroot/
git clone https://github.com/liangliangyy/DjangoBlog
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654758811-56311-git-clone.png)
2.Install Python 3.8.12
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654758825-159412-python-version-install.png)
3.Add DjangoBlog project
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654758840-918073-python-add-project.png)
Parameter Description:
- Name:Give your project a name
- Path:Select the root directory of the project,Select the previously cloned directory
- Version:Choose the python version your project needs,Choose Python Version 3.8.12 here
- Framework:The project project framework, my project here is Flask, so choose django
- Startup mode:Choose gunicorn here, You can switch other options according to your needs
- startuo file/dir:diango select the project directory to start
- Port:DjangoBlog defaults to 8000
- Run user:Start with root privileges
- Install module now:When adding a project, install the required modules according to the documentation of the project root directory requirements.txt.
- Start with the sys:Configure startup for the project
When we finish project creation, we can’t open the project normally.We need to initialize the project
After the installation is complete, the display is as follows:
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654758861-824044-python-project-ok.png)
4.Create a database for the DjangoBlog project
When creating, you need to pay attention to selecting the character set: utf8mb4
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654758880-54-python-add-data3.png)
5.Modify the DjangoBlog configuration:
Go to the DjangoBlog directory, enter the djangoblog directory, and modify the configuration file: settings.py
After commenting the original database, then add the following content, pay attention to modify it to your database name, user name, password, pay attention to the case of the database.
/www/wwwroot/DjangoBlog/djangoblog
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'djangoblog_test',
'USER': 'DjangoBlog_test',
'PASSWORD': 'P4KajxAhfJ6dMWph',
'HOST': 'localhost',
'PORT': 3306,
'OPTIONS': {'charset': 'utf8mb4'},
}
}
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654758898-987894-2.png)
Comment the configuration below, otherwise it will cause database errors later, only keep: TIME_ZONE = 'Asia/Shanghai'
#LANGUAGE_CODE = 'zh-hans' (English will be displayed after adding annotations)
#USE_I18N = True
#USE_L10N = True
#USE_TZ = True
![](https://www.bt.cn/bbs/data/attachment/forum/202204/17/173201xzsyghyogwzq6c7e.png)
configuration on the project
The Python project env used by the project
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759033-239645-python-env.png)
Please replace "8658305af42d6efded53c296d677d3ba_venv" with your project env and execute the command.
6.Start performing data migration
Generate data:
/www/wwwroot/DjangoBlog/8658305af42d6efded53c296d677d3ba_venv/bin/python3 manage.py makemigrations
/www/wwwroot/DjangoBlog/8658305af42d6efded53c296d677d3ba_venv/bin/python3 manage.py migrate
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759175-112188-makemigrations.png)
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759194-55220-python-migrate.png)
Generate super user: (create an administrator user according to the prompt)
/www/wwwroot/DjangoBlog/8658305af42d6efded53c296d677d3ba_venv/bin/python3 manage.py createsuperuser
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759214-120261-1cd50779-4077-4160-89de-86d607f40a6e.png)
Generate test data:
/www/wwwroot/DjangoBlog/8658305af42d6efded53c296d677d3ba_venv/bin/python3 manage.py create_testdata
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654760972-330723-7a92e85a-1431-43a0-af64-56b7ba61982d.png)
Collect static files:
/www/wwwroot/DjangoBlog/8658305af42d6efded53c296d677d3ba_venv/bin/python3 manage.py collectstatic --noinput
/www/wwwroot/DjangoBlog/8658305af42d6efded53c296d677d3ba_venv/bin/python3 manage.py compress --force
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759258-617616-python.png)
Restart the DjangoBlog project
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759278-358213-djangoblog.png)
7.The port 8000 used by DjangoBlog is released in Security
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759292-961779-python-add-port.png)
try to access
Open the browser: http://127.0.0.1:8000/
and you can see the effect
Replace the ip address with your server address.
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759306-213219-4ded8991-a5c9-42bc-89a4-879703d6ad7a.png)
8.Map the DjangoBlog project to a web service (nginx/apache), and nginx/apache is responsible for forwarding the request to our Python project on the backend
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759322-842927-python-3.png)
9.Static file configuration
Add the following to site config URL rewrite:
location /static/ {
alias /www/wwwroot/DjangoBlog/collectedstatic/;
expires max;
access_log off;
log_not_found off;
}
location /media {
alias /www/wwwroot/DjangoBlog/uploads/;
expires max;
}
location ~ \.py$ {
return 403;
}
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759349-347730-python-url-rewrite.png)
10.DjangoBlog project deploys SSL
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759368-811384-python-ssl.png)
Access effect:
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759390-647971-python-ssl3.png)
Login background error after deploying SSL:
https://129djangoblog.com/admin
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759417-332153-python-error-https.png)
Solution:
Modify the configuration file: /www/wwwroot/DjangoBlog/djangoblog/settings.py
ALLOWED_HOSTS = ['*', '127.0.0.1', '129djangoblog.com']
# django 4.0新增配置
CSRF_TRUSTED_ORIGINS = ['https://129djangoblog.com']
Replace 129djangoblog.com with your domain name, then go to Python Manager to restart the DjangoBlog project.
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759444-778652-python-https-ok.png)
![](https://www.aapanel.com/forum/assets/files/2022-06-09/1654759460-426559-python-129djangoblog.png)
References:
https://github.com/liangliangyy/DjangoBlog/blob/master/docs/README-en.md
https://www.bt.cn/bbs/thread-90005-1-1.html