如何在使用 Ajax 时在 django 视图中使用 Httpresponse
我正在使用这个
def ajax_create( request ):
if request.is_ajax():
form = SourceForm()
template = 'ajax_form.html'
data = {
'form': form,
}
return render_to_response( template, data,
context_instance = RequestContext( request ) )
我收到此错误
ajax_create did not return an HttpResponse object
I am using this
def ajax_create( request ):
if request.is_ajax():
form = SourceForm()
template = 'ajax_form.html'
data = {
'form': form,
}
return render_to_response( template, data,
context_instance = RequestContext( request ) )
I get this error
ajax_create didn't return an HttpResponse object
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您确定您的请求是 ajax 调用吗?看起来不像。
尝试:
Are you sure your request is an ajax call ? It doesn't look like it.
Try:
如果这是您的整个视图函数,也许
if request.is_ajax():
返回 False?通常,在创建 Django 视图函数时应遵循以下模式:
Perhaps
if request.is_ajax():
is returning False, if that's your entire view function?Typically, you should follow this pattern when making Django view functions:
它没有进入你的“如果”范围。它返回 None
https://docs.djangoproject .com/en/1.3/ref/request-response/#django.http.HttpRequest.is_ajax
检查您的 ajax 调用并确保它返回一些内容,以防请求不是阿贾克斯
It's not entering to your "if" scope. it returns None
https://docs.djangoproject.com/en/1.3/ref/request-response/#django.http.HttpRequest.is_ajax
Check your ajax call and make sure it returns something in case the request is not ajax