1、宝塔快速部署Django项目
python项目管理器

2、python项目管理器 > 项目管理 > 添加项目

python -m pip freeze > requirements.txt

注:这个requirements.txt名字不能变,而且这个requirements.txt需要生成在项目根目录里。这里导出可能会有BUG,导致后续出现问题,如果有问题,本文下面有解决方法

requirements.txt格式如下:

amqp==5.0.5
asgiref==3.3.1
billiard==3.6.3.0
celery==5.0.5
certifi==2020.12.5
chardet==4.0.0
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
Django==3.1.7
django-filter==2.4.0
django-redis==4.12.1
django-sslserver==0.22
djangorestframework==3.12.2
djangorestframework-jwt==1.11.0
elasticsearch==7.11.0
idna==2.10
Jinja2==2.11.3
kombu==5.0.2
lxml==4.6.3
Markdown==3.3.4
MarkupSafe==1.1.1
paho-mqtt==1.5.1
Pillow==8.1.2
prompt-toolkit==3.0.16
PyJWT==1.7.1
PyMySQL==1.0.2
pytz==2021.1
redis==3.5.3
requests==2.25.1
six==1.15.0
sqlparse==0.4.1
urllib3==1.26.3
vine==5.0.0
wcwidth==0.2.5

3、映射域名

这里就点击映射之后,输入你的域名就可以了。

注:如果没有域名,输入你的公网IP即可(不加端口号的哦)。

4、更改网站项目地址

点击之后,会出现如下图所示的对话框

5、完成

此时,你的项目就已经部署完成了

注:这里没有说绑定域名和SSL证书,网上也会有许多此类教程,如果需要可以私聊我添加上来

2、常见问题与解决方法

当我们用宝塔去部署文件的时候,会使用到python项目管理器

此时,有几个坑

抱歉,出错了:
Traceback (most recent call last):
File "class/flask_sockets.py", line 30, in __call__
handler, values = adapter.match()
File "/www/server/panel/pyenv/lib/python3.7/site-packages/werkzeug/routing.py", line 1945, in match
raise NotFound()
werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "class/public.py", line 335, in ReadFile
f_body = fp.read()
File "/www/server/panel/pyenv/lib/python3.7/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf
1、宝塔如果使用python项目管理器,需要时centos7.x
2、我们会将python的模块导出为一个requirements.txt,而这个文件有时候会报错(如上图所示),在本地是可以查看的,而上传到宝塔服务器上的时候这个文件就会编码不被兼容,无法正确读取文件,当我们创建项目的时候就会报错
解决方法:最简单的,在本地新建一个requirements.txt,将里面的内容copy进去,然后上传到服务器,这样就可以了
3、启动文件/文件夹选择的是:譬如这个项目叫做test,那么test项目里面还有一个test文件夹,选择的是这个