Ubuntu 上使用uwsgi部署django项目

在Ubuntu 上使用uwsgi来部署

1.将django项目发送到服务器上
2.将settings.py的STATICFILES_DIRS 注释
 添加 STATIC_ROOT = os.path.join(BASE_DIR, "static")
收集一下静态文件
python manage.py collectstatic
收集完成之后,将STATIC_ROOT注释 
将STATICFILES_DIRS放开
3.pip isntall uwsgi
4. 执行:
uwsgi --http :80 --chdir 项目的绝对路径  --module app.wsgi --static-map=/static=static

 

使用screen 在后台挂载项目

1.下载screen: 
apt  install screen
2. screen -S name
3. 运行你的命令
4.另开一个窗口 screen -ls
5. 连接到会话:  screen -r yourname
6.在创建name的窗口输入Ctrl_a+d 保存进程并退出
7. 输出日志:
    在创建的name的窗口输入Ctrl+a+h  会提示日志将要输出到项目的hardcopy.0 文件中
8.杀死screen 会话
screen -X -S  [session # you want to kill]  quit

  

给Css 文件添加版本号:

import os
import re
import uuid


def file_extension(path):
    return os.path.splitext(path)[1]


basePath = r"......."  # 这里改成存放html的路径,支持多层
html_list = []


def find_html(path):
    files = os.listdir(path=path)

    for item in files:
        abs_path = os.path.join(path, item)
        if not os.path.isdir(abs_path) and file_extension(abs_path) == ".html":
            html_list.append(abs_path)

        if (os.path.isdir(abs_path)):
            find_html(abs_path)


def deal_html(html_list):
    for html_path in html_list:
        html_file = open(html_path, "r+", encoding='UTF-8')
        content = html_file.read()
        ret = re.findall(r'<link href="{% static "(.*).css" %}"(.*)>', content)
        if not ret:
            res1 = re.sub(r'<link href="(.*).css(.*)">',
                          lambda x: '<link ' + 'href="' + x.group(1)+'.css?v=' + uuid.uuid1().hex+'" '+ 'rel="stylesheet"'+ '>',content)  
        else:
            res1 = re.sub(r'<link href="{% static "(.*).css" %}"(.*)>',
                          lambda x: '<link ' + 'href="/static'+ x.group(1).strip() + '.css?v=' + uuid.uuid1().hex + '" '+ x.group(
                              2) +'>',
                          content)

        html_file.seek(0)
        html_file.truncate()
        html_file.write(res1)
        html_file.close()


if __name__ == '__main__':
    find_html(basePath)
    print(html_list)
    deal_html(html_list)

  

  

  

 

posted @ 2019-12-04 17:31  Py浪涛  阅读(645)  评论(1编辑  收藏  举报
你想听歌吗o((;=゚ 3゚ =))o~♪