部署python3.6下的django

时间:2022-03-16 08:32:56

首先是安装好nginx,配置web目录,配置文件在confi.d中,

server {
    # the port your site will be served on
    listen      ;
    # the domain name it will serve for
    server_name localhost; # substitute your machine's IP address or FQDN
    charset     utf-;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /var/www/myweb/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /var/www/myweb/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        include    /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
        uwsgi_pass ;
    }
}

修改nginx配置文件后,需要重新启动nginx

service nginx restart

把web文件git上传到/var/www/myweb中去

可以使用pycharm的自动同步代码工具,自动上传代码到服务器,速度特别快。

部署python3.6下的django

在settings.py中有一项wsgi的配置:

部署python3.6下的django

服务器端安装插件

pip install django
pip install mysqlclient
pip install pillow

迁移数据

python manage.py makemigrations
python manage.py migrate

启动服务

screen -S xyz
uwsgi -s: -w web.wsgi

ctrl +a+d 退出screen

部署python3.6下的django

-----------------------

登陆后台发现没有样式了……只好把文件复制进去……

部署python3.6下的django

注意,在第二个Lib文件夹下的文件,复制到根目录对应的文件夹中,上传到服务器就好了。之前需要在服务器上创建超级管理员。

部署python3.6下的django