在Ubuntu 上使用uwsgi来部署
11.将django项目发送到服务器上 22.将settings.py的STATICFILES_DIRS 注释 3 添加 STATIC_ROOT = os.path.join(BASE_DIR, "static") 4收集一下静态文件 5python manage.py collectstatic 6收集完成之后,将STATIC_ROOT注释 7将STATICFILES_DIRS放开 83.pip isntall uwsgi 94. 执行: 10uwsgi --http :80 --chdir 项目的绝对路径 --module app.wsgi --static-map=/static=static
使用screen 在后台挂载项目
11.下载screen: 2apt install screen 32. screen -S name 43. 运行你的命令 54.另开一个窗口 screen -ls 65. 连接到会话: screen -r yourname 76.在创建name的窗口输入Ctrl_a+d 保存进程并退出 87. 输出日志: 9 在创建的name的窗口输入Ctrl+a+h 会提示日志将要输出到项目的hardcopy.0 文件中 108.杀死screen 会话 11screen -X -S [session # you want to kill] quit
给Css 文件添加版本号:
1import os 2import re 3import uuid 4 5 6def file_extension(path): 7 return os.path.splitext(path)[1] 8 9 10basePath = r"......." # 这里改成存放html的路径,支持多层 11html_list = [] 12 13 14def find_html(path): 15 files = os.listdir(path=path) 16 17 for item in files: 18 abs_path = os.path.join(path, item) 19 if not os.path.isdir(abs_path) and file_extension(abs_path) == ".html": 20 html_list.append(abs_path) 21 22 if (os.path.isdir(abs_path)): 23 find_html(abs_path) 24 25 26def deal_html(html_list): 27 for html_path in html_list: 28 html_file = open(html_path, "r+", encoding='UTF-8') 29 content = html_file.read() 30 ret = re.findall(r'<link href="{% static "(.*).css" %}"(.*)>', content) 31 if not ret: 32 res1 = re.sub(r'<link href="(.*).css(.*)">', 33 lambda x: '<link ' + 'href="' + x.group(1)+'.css?v=' + uuid.uuid1().hex+'" '+ 'rel="stylesheet"'+ '>',content) 34 else: 35 res1 = re.sub(r'<link href="{% static "(.*).css" %}"(.*)>', 36 lambda x: '<link ' + 'href="https://my.oschina.net/static'+ x.group(1).strip() + '.css?v=' + uuid.uuid1().hex + '" '+ x.group( 37 2) +'>', 38 content) 39 40 html_file.seek(0) 41 html_file.truncate() 42 html_file.write(res1) 43 html_file.close() 44 45 46if __name__ == '__main__': 47 find_html(basePath) 48 print(html_list) 49 deal_html(html_list)