该视图没有返回一个HttpResponse对象。它返回无 [英] The view didn't return an HttpResponse object. It returned None instead

查看:4125
本文介绍了该视图没有返回一个HttpResponse对象。它返回无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下简单的观点。为什么会导致此错误?



视图auth_lifecycle.views.user_profile未返回HttpResponse对象。它返回了无。

 呈现用户认证生命周期项目的网页。
from django.shortcuts import render
from django.template import RequestContext
from django.contrib.auth import authenticate,login

def user_profile(request )
显示登录用户唯一的信息。

user = authenticate(username ='superuserusername',password ='sueruserpassword')
登录(请求,用户)

render(request,'auth_lifecycle / user_profile.html',
context_instance = RequestContext(request))
pre>

解决方案

因为视图必须返回 render ,不只是调用它。将最后一行更改为

  return render(request,'auth_lifecycle / user_profile.html',
context_instance = RequestContext请求))


I have the following simple view. Why is it resulting in this error?

The view auth_lifecycle.views.user_profile didn't return an HttpResponse object. It returned None instead.

"""Renders web pages for the user-authentication-lifecycle project."""
from django.shortcuts               import render
from django.template                import RequestContext
from django.contrib.auth            import authenticate, login

def user_profile(request):
    """Displays information unique to the logged-in user."""

    user = authenticate(username='superuserusername', password='sueruserpassword')
    login(request, user)

    render(request, 'auth_lifecycle/user_profile.html',
           context_instance=RequestContext(request))

解决方案

Because the view must return render, not just call it. Change the last line to

return render(request, 'auth_lifecycle/user_profile.html',
           context_instance=RequestContext(request))

这篇关于该视图没有返回一个HttpResponse对象。它返回无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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