gpt4 book ai didi

python - 删除了InDjango110警告: The context_instance argument of render_to_string is deprecated

转载 作者:行者123 更新时间:2023-12-01 03:50:22 25 4
gpt4 key购买 nike

对于其中一个应用程序,我在使用管理面板的 Django 1.9.x 项目中重载了“删除所选对象”方法。为此,我有一个与此类似的代码:

from django.contrib.admin import helpers
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext

class MAdmin(admin.ModelAdmin):
actions = ['delete_selected']

def delete_selected(self, request, queryset):
if 'apply' in request.POST:
# User has confirmed deletion of items
return HttpResponseRedirect(request.get_full_path())
else:
# User must confirm if they wish to delete selected items
return render_to_response('admin/confirm_delete.html', { 'queryset': queryset, 'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME }, context_instance=RequestContext(request))

最后一行在控制台中产生以下警告:

.../virtualenv/lib/python2.7/site-packages/django/shortcuts.py:45: RemovedInDjango110Warning: The context_instance argument of render_to_string is deprecated. using=using)

我试图找到一些资源来解释如何根据版本 1.10.x“更新”语法,但我一直无法找到。

类似的问题已经被问过 here但略有不同,因为 OP 显式调用 render_to_string 而我没有。

我应该如何更新上面的调用以使警告消失?

最佳答案

是的,修复它的“正确”方法是更新它。根据documentation, they recommend using render()

Deprecated since version 1.8: The context_instance argument is deprecated. Use the render() function instead which always makes RequestContext available.

如果您确实想抑制此警告(非常不推荐),可以使用 SILENCE_SYSTEM_CHECK 设置。

More on the system check can be found here

关于python - 删除了InDjango110警告: The context_instance argument of render_to_string is deprecated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38336440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com