When deploying Django project on centos7, there will be an error of importerror: cannot import name middlewaremin

Deployment on embedded devices has been fine, but this problem occurs on Linux Centos7, usually due to versioning issues.
Solution Install pip3 install Django==1.11.1
However, the following 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)
]

to:

# 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)
]

Due to version issues, this may cause the following problems

render_to_string() got an unexpected keyword argument ‘context_instance’

Solution:

context must be a dict rather than RequestContext.

is when the context becomes
{
“context”:context
}

Due to the version upgrade, the previous code

return render_to_response(‘info_count.html’, {}, context_instance=RequestContext(request))

should be rewritten to something like this.

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})

Similar Posts: