首页 > 解决方案 > ImportError:无法从“django.shortcuts”导入名称“render_to_response”

问题描述

from django.shortcuts import render_to_response
ImportError: cannot import name 'render_to_response' from 'django.shortcuts' (C:\Users\gtdra\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\shortcuts.py)

当我迁移django-chroniker到我的 django 项目时出现此错误,我读到render_to_response自 Django 2.0 以来已被删除,我该如何解决此错误?感谢您

标签: pythondjango

解决方案


render_to_response不可用django.shortcuts(render_to_response 快捷方式在 Django 2.0 中已弃用,在 Django 3.0 中已删除。)。你可以render像下面这样使用

from django.shortcuts import render

def myview(request):
    return render(request, 'template.htmll', {'hi': 'hello'})


推荐阅读