render_to_string()得到了意外的关键字参数'status' [英] render_to_string() got an unexpected keyword argument 'status'

查看:124
本文介绍了render_to_string()得到了意外的关键字参数'status'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行django应用程序并收到以下错误:

I am running a django application and getting the following error:

TypeError at /login

render_to_string() got an unexpected keyword argument 'status'

Request Method:     GET

Request URL:    http://10.107.44.122:8002/login?next=/

Django Version:     1.7.1

Exception Type:     TypeError

Exception Value: render_to_string() got an unexpected keyword argument 'status'

Exception Location:     /usr/local/lib/python2.7/dist-packages/django/shortcuts.py in render_to_response, line 23

Python Executable:  /usr/bin/python

Python Version:     2.7.6

我唯一想到错误可能出处的地方是:

The only place I could think of where the error might be coming from is :

render_to_response('login.html', context, status=status, context_instance=RequestContext(request))

应该将

status用作render_to_response的关键字,那么为什么会出现此错误?

status is supposed to be expected keyword for render_to_response, then why this error?

推荐答案

您可以使用render快捷方式代替render_to_response.在所有版本的Django中,render方法均采用status参数.无论如何,这是一种更好的方法,因为您不需要提供RequestContext.

You could use the render shortcut instead of render_to_response. The render method does take a status argument in all versions of Django. It's a nicer method to use anyway, because you don't need to supply a RequestContext.

from django.shortcuts import render

def my_view(request):
    context ={'foo': 'bar'}
    status = 200
    return render(request, 'login.html', context, status=status)

这篇关于render_to_string()得到了意外的关键字参数'status'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆