2013-03-10 122 views
1

嘿傢伙我正在開發一個項目管理網站使用django,我得到這個錯誤The view equipo.frontends.views.hoddashboard didn't return an HttpResponse object當我認證用戶登錄儀表板。django視圖雖然返回一個不返回httpresponse對象

我views.py如下:

from django.http import HttpResponse 
    from django.template import RequestContext 
    from django.shortcuts import render_to_response 
    from django.views.generic.simple import direct_to_template 
    from django.template.loader import get_template 
    from django.template import Context 
    from django.forms import * 
    from django.contrib.auth import authenticate 
    from django.contrib import auth 
    from django.http import HttpResponseRedirect 

    def hoddashboard(request): 
     if request.method=='POST': 
      username=request.POST.get('Username') 
      password=request.POST.get('Password') 
      user=authenticate(username=username,password=password) 
      if user is not None: 
       auth.login(request, user) 
       team="team.png" 
       t={'team1':team} 
       return HttpResponseRedirect('/home/aditya/Desktop/equipo/equipo/frontend  /templates/hodnewdash.html') 

和我的html頁面如下:

<html> 
     <head> 
      <title>hod-login</title> 
      <style type="text/css">.hod2{position:absolute;left:160;top:150;} 
       .hod1{position:absolute;left:870;top:180;} 
       .hod2{position:absolute;left:160;top:150;} 
      </style> 
     </head> 
     <body> 
      <div style='position:absolute;z-index:0;left:0;top:0;width:100%;height:100%'> 
     <img src='{{MEDIA_URL}}hod.png' style='width:100%;height:100%' alt='[]' /> 
    </div> 
      <img height="300" width="450" class="hod2" src="{{MEDIA_URL}}hod1.jpeg" /> 
      {%block content %} 
      <form action="hodnewdash.html" class="hod1" method="POST" name="hodlogin">{% csrf_token %} 
       <label>Username:</label><input type="text" name="uname" size="20"> </input><br /> 
       <br /> 



       <label>Password:</label><input type="password" name="pwd" value="" size="20" /> 
       <br /><br /> 
       <input type="submit" value="submit" name="submit" /> 
      <input type="hidden" name="next" value="hodnewdash.html" /> 
      </form> 
     {% endblock %} 
     </body> 
    </html> 

回答

0

如果您的網址直接請求(用GET)你不返回任何東西,並且還有其他一些未處理的條件:

def hoddashboard(request): 
     if request.method=='POST': 
      # do stuff 
      if user is not None: 
       # do stuff 
       return redirect('/some/url') 
      else: 
       return redirect('/some/url2/') 
     else: 
      return redirect('/somewhere/else/') 
0

您應該查看來自Bu的響應rhan,方法hoddashboard的骨架更好。

任何方式,你沒有以正確的方式使用HttpResponseRedirect,你應該傳遞參數的URL你想重定向到用戶。例如,如果你想要用戶去http://yoursite.com/dashboard/必須使用:

return HttpResponseRedirect('/dashboard/') 

這種反應會運行在你的代碼中的儀表盤方法,並返回其響應。

您可以在此處將文檔變爲紅色:https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponseRedirect