【问题标题】:django httpresponse problemdjango httpresponse 问题
【发布时间】:2011-03-30 13:47:58
【问题描述】:

我的问题是什么时候将我的用户名和密码字段留空,它会显示错误 "(视图 PatientInfo.views.login_check 没有返回 HttpResponse 对象。")

这里我为我的默认登录页面使用登录处理程序,并在它成功登录时使用 login_check。 在这里,将用户名或密码字段留空,它不会返回响应。即使我使用 HttpResponseRedirect 如下,但它不起作用。

def login(request):

    template = "../templates/admin/login.html"
    data ={}
    return render_to_response( template, data, 
                              context_instance = RequestContext( request ) )


def login_check(request):

    user = request.POST['username']
    pas = request.POST['password']

    if (user is None or pas is None):
       if (user != "aa" and pas != "aa"):      

          return HttpResponseRedirect('/login/')

    else:
        if (user == "aa" and pas =="aa"):
            template = "../templates/admin/index.html"
            data = {}
            return render_to_response( template, data, context_instance = RequestContext( request ) )

【问题讨论】:

  • 您能否在发布时尝试将代码缩进四个空格,以便以可读的方式显示。如果不确定是否正确,请查看预览。
  • 您已经以不同的形式发布了相同的问题 3 或 4 次。您仍然没有接受使用 Django 的登录功能的建议,该功能完全符合您的需求,这让我怀疑这是一项任务或其他什么。

标签: django


【解决方案1】:

您忘记了user 不是'aa'pas 不是'aa' 的条件。用有用的东西填写else 子句。

【讨论】:

  • 是的,我确实用户不是 'aa' 或 pas 不是 'bb' 实际上我没有开始 httpresponse 它在这里显示错误...而且我在我的登录页面 html 中使用了 login_check 处理程序login_check 处理程序并在我提供用户名 aa 和密码 aa 时成功显示我想要的页面,但问题出在错误的用户名上,密码它显示 httpresponse 没有对象返回错误
  • 当然可以。你忘了在else 子句中添加一些有用的东西。
  • def login_check(request): if request.method == "POST": user = request.POST['username'] pas = request.POST['password'] if (user is None or pas is None): if (user is not 'aa' and pas is not 'aa') return render_to_response( template, data, context_instance = RequestContext( request ) )
  • 你的 other else 部分。你知道,那个不存在的吗?
  • else: if (user == "aa" and pas =="aa"): template = "../templates/admin/index.html" data = {} return render_to_response(template, data, context_instance = RequestContext( request ) ) 实际上我上面提到了我的代码..你请仔细阅读它..我希望你能提前弄清楚我的问题
猜你喜欢
  • 1970-01-01
  • 2010-10-26
  • 2019-04-04
  • 2013-06-12
  • 1970-01-01
  • 2015-05-24
  • 2021-08-14
  • 2011-04-08
  • 1970-01-01
相关资源
最近更新 更多