2013-06-19 58 views
0

URL未更改,數據在用戶登錄後未提取。網址未更改,僅在登錄後呈現模板

的URL沒有改變登錄後(我希望改變127.0.0.1:8000/employer/home)

@login_required 
def home(request): 
    emp=Employer.objects.get(user=request.user) 
    jb=Job.objects.filter(employer=emp).order_by("-postdate") 
    return render(request,'employer/home.html',{'jobs':jb})#,{'employer':emp}) 

僱主/ home.html的

<table class="table table-hover table-bordered"> 
<tr><th>Job ID</th><th>Title</th><th>Posted on</th></tr> 
{% for job in jobs %} 
<tr> 
<td><a href="{% url quorum.views.questions job.pk %}">{{ job.pk }}</a></td> 
<td>{{ job.title }}</td> 
<td>{{ job.postdate }}</td> 
</tr> 
{% endfor %} 
</table> 

的login.html

<form class="form-signin" action="" method="post">{% csrf_token %} 
<h4 class="form-signin-heading">Sign in to my account...</h4> 
{% if errors %} 
<p class="text-error">Sorry, that's not a valid username or password</p> 
{% endif %} 

<input type="text" id="username" class="input-block-level" name="username" placeholder="UserID"> 
<input type="password" id="password" class="input-block-level" name="password" placeholder="Password"> 
<p style="text-align:right;"><a href="/accounts/password/reset/">Forgot</a> your password?</p> 

<button class="btn btn-large btn-success" type="submit" value="login">Sign in</button> 

</form> 

回答

2

你需要告訴它在登錄後使用next url參數去哪裏:

<form class="form-signin" action="{% url django.contrib.auth.views.login %}?next=employer/home/" method="post"> 

或設置設置LOGIN_REDIRECT_URL

這裏請求登錄後當contrib.auth.login觀點得不到下一參數重定向的URL。

+0

它工作謝謝 – suhailvs