网站部署第14天
由于旧的服务器过期了。租了新的服务器.发现Fabric2.0已经不支持Python2了。使用旧版Fabric1.x又会出现各种问题,比如加密解密库会无法使用,唯一好的方法是用Fabric3 1.14可以兼容1.x,2.x fabfile文件。下载链接在这 https://pypi.org/project/Fabric3/ **或者直接(注意是python3环境pip3)** ```bash pip3 install Fabric3==1.14.post1 ```
由于旧的服务器过期了。租了新的服务器.发现Fabric2.0已经不支持Python2了。使用旧版Fabric1.x又会出现各种问题,比如加密解密库会无法使用,唯一好的方法是用Fabric3 1.14可以兼容1.x,2.x fabfile文件。下载链接在这 https://pypi.org/project/Fabric3/ **或者直接(注意是python3环境pip3)** ```bash pip3 install Fabric3==1.14.post1 ```
部署文件在我的Github项目可找到:[https://github.com/yemaobumei/mysite](https://github.com/yemaobumei/mysite) 阿里云服务器需配置网络安全组 HTTP 显示为 80/80。 实例作为网站或 Web 应用的服务器。 - 第一步 安装nginx,fabric,virtualenv **注意安装包对应的python版本** ```bash sudo apt-get install nginx sudo service nginx start sudo pip3 install Fabric3==1.14.post1 sudo pip2 install virtualenv ``` 此时输入网站域名或者IP就能看到welcome to nginx!测试页面 - 第二步 运行自动部署文件fabfile.py 在包含fabfile.py文件的目录下,运行 ```bash fab deploy ```
当包含static文件夹的主目录/home 权限不够时,网页访问会出现403。解决办法,chmod 775增加一般用户权限。
多对多字段表单提交时候处理方法 ManyToManyField models.py ```python class Article(models.Model): tags=models.ManyToManyField(Tag,blank=True) #博客标签 class Tag(models.Model): name=models.CharField(max_length=50,blank=True) ``` template端: ```html {%for tag in tags%} <label><input type="checkbox" name="tag_list" value={{tag.name}}> {{tag.name}}</label> {%endfor%} ``` 后台views.py中 ```python tag_list=request.POST.getlist("tag_list") for each in new_article.tags.all(): new_article.tags.