ImportError: can not import name 'render_to_response' solution

  A few days before the official launch Django 3.0 framework, projects in the K8S deployment startup, reported this error: ImportError: can not import name ' render_to_response' from 'django.shortcuts'. Then simply under investigation, into the container with pip3 show django command to see the upgrade to the 3.0 framework (previously has been using Django 2+), see official information found Django 3.0 has render_to_response removed . Because some code with render_to_response, and our packaged mirror when not specified version of Django, so being given the boot. There are two solutions:

 

method one

 Django specified version Installation version (3.0 or less), such as:

pip3 install django==2.1.3

 

Method Two

 Instead of using render render_to_response.

 The same point: both show template page .

 Different points: render method can be up to three parameters, one request parameter, the second is to be rendered html template file, the third is to save the data dictionary specific parameters. Its role is to fill the data into the template file, and finally return the result to the browser. render automatically RequestContext , and render_to_response need coding into it.

return render(request,"information.html",{"name":"test","password":"123456"})
return render_to_response("information.html",{"name":"test","password":"123456"},context_instance = RequestContext(request))

 

 

 

Guess you like

Origin www.cnblogs.com/shenh/p/11993679.html