Centos7上部署Django项目会出现 ImportError: cannot import name MiddlewareMixin的错误
在嵌入式设备上部署一直没问题,而部署在Linux Centos7 上出现此问题,一般是因为版本问题导致。
解决方法 安装 pip3 install Django==1.11.1
然而又出现下面 ImportError: cannot import name patterns
vim touch/extra_apps/DjangoUeditor/urls.py
# coding:utf-8
from django import VERSION
if VERSION[0:2] > (1, 3):
from django.conf.urls import patterns, url
else:
from django.conf.urls.defaults import patterns, url
from .views import get_ueditor_controller
urlpatterns = [
url(r'^controller/$', get_ueditor_controller)
]
改为:
# coding:utf-8
from django import VERSION
if VERSION[0:2] > (1, 3):
from django.conf.urls import url
else:
from django.conf.urls.defaults import url
from .views import get_ueditor_controller
urlpatterns = [
url(r'^controller/$', get_ueditor_controller)
]
由于版本问题,顺而可能引起以下问题
render_to_string() got an unexpected keyword argument 'context_instance'
解决方法:
context must be a dict rather than RequestContext.
就是context变为
{
"context":context
}
由于版本升级,之前代码中
return render_to_response('info_count.html', {}, context_instance=RequestContext(request))
应该 改写为类似这种:
from django.shortcuts import render
return render(request, "info_main.html", {'time_refresh': time_refresh,
'time_refresh_long': time_refresh_long,
'time_refresh_net': time_refresh_net,
'version': version})