Django的项目的重新部署
来源:互联网 发布:淘宝网店开店流程 编辑:程序博客网 时间:2024/06/06 04:03
作为完全没有接触过python的小白,希望大家多多指教
临时接到部署一个几年前写的Django的项目的重新部署。花了近两天遇到了一些问题写下来,希望能帮助别人也能给自己留个备份
这是mentor发给我部署的指导
a) Install all the python requirements that exist in the requirements.txt file
This will be failing for multiple packages as it is outdated, so wherever it fails, you can manually install the package, and remove the entry from the .txt file
b) Install https://www.phusionpassenger.com/library/install/apache/install/oss/trusty/ - wsgi (and set it up) - I don’t have any experience with this, so you will have to do some research
c) Setup django - follow this tutorial https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
a)$ pip install -r requirements.txt 因为代码年份比较久远,所以很多的package比较久远。每次遇到一个错误,就根据提示的line把package注释了然后手动安装新的package。这样也为后来埋下了一些坑,有一些版本兼容问题。
b) 推荐链接
https://www.phusionpassenger.com/library/install/apache/install/oss/trusty/
Window 不支持。能根据OS 的版本来选择安装方法。非常感谢作者!
c)教程还是清楚明了了。根据我的项目情况我按照教程来创建了 a Python virtual environment。需要注意的是,要把manag.py os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “xxx.settings”)
xxx.setting 指向自己项目的setting。
按照教程跑项目。
总结一下遇到的问题和解决方法(都不是原创,只是总结一下):
P1
from django.template.engine import Engine
ImportError: No module named engine
由于版本问题,根据我的equirements.txt 安装的djanggo的版本是1.7.2
解决:升级版本 pip install –upgrade django
P2
from django.conf.urls import patterns, include, url
ImportError: cannot import name patterns
由于版本问题,由于我升级了版本,djanggo 1.8+以后的版本不支持以下的写法
需要改成:
(手动把项目组urls.py的文件都改成这样)
P3
Exception Type: TemplateDoesNotExist at /
Exception Value: base.html
解决
添加BASE_DIR = os.path.dirname(os.path.abspath(file))
去掉 TEMPLATE_DIRS and TEMPLATE_LOADERS.
加上
TEMPLATES = [
{
‘BACKEND’: ‘django.template.backends.django.DjangoTemplates’,
‘DIRS’: [‘/xxx/xxxx’],#你的路径
‘APP_DIRS’: True,
‘OPTIONS’: {
‘context_processors’: [
‘django.template.context_processors.debug’,
‘django.template.context_processors.request’,
‘django.contrib.auth.context_processors.auth’,
‘django.contrib.messages.context_processors.messages’,
],
},
},
]
P4
NoReverseMatch at /
u’djdt’ is not a registered namespace
解决
在每个urls.py 的文件下面加上
if settings.DEBUG:
import debug_toolbar
urlpatterns = [
url(r’^debug/’, include(debug_toolbar.urls)),
] + urlpatterns
如下
还遇到了很多问题,但是还是比较容易google到的,就不一一列出来啦!
- Django的项目的重新部署
- django项目部署 - 部署前的准备
- Myeclipse 修改jsp项目要重新部署的解决办法
- idea2016 修改jsp页面需要重新部署项目的问题
- 重新部署项目后,上传的图片在浏览器中
- Django的SAE部署
- django的apache部署
- python的django项目uwsgi+nginx的部署
- Django项目实际部署与开发环境的问题
- django项目部署到SAE上的个人博客
- 关于django项目部署在服务器上的二三事
- 跨过Nginx上基于uWSGI部署Django项目的坑
- 在自己的服务器上部署Django项目
- 使用nginx + uwsgi socket的方式来部署Django项目
- django 将删除的表重新生成
- apache2部署django的错误
- Django 在服务器的部署
- Ubuntu下Django的部署
- 项目实训——BBS论坛开发(一)
- LeetCode编程练习
- LeetCode编程练习
- STL-deque容器
- LeetCode编程练习
- Django的项目的重新部署
- kali 源
- ajax原生js面向对象封装及开发时遇到的问题
- LeetCode编程练习
- hadoop2.7伪分布安装配置
- LeetCode编程练习
- 谷歌扩展程序开发常用工具(Develop Tools)
- LeetCode编程练习
- antrl4学习(三)——用idea实现简单计算器