0
我在實現Django會話時遇到了一些問題。我有一個員工列表頁面,上面有一個篩選器選項。根據字段和文本框中輸入的文本進行過濾。過濾的用戶顯示在filter.html頁面中;點擊用戶名就會進入該用戶的個人資料頁面。現在我想返回到顯示過濾用戶的過濾頁面(filter.html)的上一頁(在員工檔案頁面中有一個後退按鈕)。我想這可以通過會議完成。但我不確定我使用會話的方式是否正確。請幫我解決這個問題,因爲我是Django的新手。會後我的代碼在這裏:使用Django會話
def filter(request):
val=request.POST.get('designation')
val2=request.POST.get('choices')
val3=request.POST.get('textField')
if val2=='Designation':
newData = EmployeeDetails.objects.filter(designation=request.POST.get('textField'))
request.session['session_textField']="textField"
request.session['session_choices']="choices"
session_textField = request.session["session_textField"]
session_choices = request.session["session_choices"]
print session_textField,session_choices
elif val2=='Name':
newData = EmployeeDetails.objects.filter(userName=request.POST.get('textField'))
request.session['session_textField']="textField"
request.session['session_choices']="choices"
session_textField = request.session["session_textField"]
session_choices = request.session["session_choices"]
print session_textField,session_choices
elif val2=='EmployeeID':
newData = EmployeeDetails.objects.filter(employeeID=request.POST.get('textField'))
request.session['session_textField']="textField"
request.session['session_choices']="choices"
session_textField = request.session["session_textField"]
session_choices = request.session["session_choices"]
print session_textField,session_choices
elif val2=='Project':
newData = EmployeeDetails.objects.filter(project=request.POST.get('textField'))
request.session['session_textField']="textField"
request.session['session_choices']="choices"
session_textField = request.session["session_textField"]
session_choices = request.session["session_choices"]
print session_textField,session_choices
elif val2=='DateOfJoin':
newData = EmployeeDetails.objects.filter(dateOfJoin=request.POST.get('textField'))
request.session['session_textField']="textField"
request.session['session_choices']="choices"
session_textField = request.session["session_textField"]
session_choices = request.session["session_choices"]
print session_textField,session_choices
else:
return render_to_response('filter.html')
return render_to_response('filter.html',{'newData':newData,'val2':val2})
Filter.html
<html>
<h3><br><br>
The Filtered Data
</h3>
<body>
<br>
{%for data in newData%}
<a href ="http://10.1.0.90:8080/singleEmployee/{{data.id}} ">
{{ data.userName}}<br>
{%endfor%}
</body><br><br><br><br>
<a href ="http://10.1.0.90:8080/employeeList/ "> Home Page </a>
</html>
員工檔案的html頁面
<table>
<tr> <td>Name: {{ empSelect.userName }} </td> </tr><td>
<tr> <td>Designation: {{ empSelect.designation }} </td> </tr><td>
<tr> <td>Employee ID: {{ empSelect.employeeID }} </td> </tr><td>
<tr> <td>Contact Number: {{ empSelect.contactNumber }} </td> </tr><td>
<tr> <td>Project: {{ empSelect.project }} </td> </tr><td>
<tr> <td>Date Of Join: {{ empSelect.dateOfJoin }} </td> </tr><td>
</table></h4><br>
<input type="submit" value="Delete User" onClick="window.location.href='/userDelete/{{empSelect.id}}'"/>
<input type="submit" value="Update User" onClick="window.location.href='/userUpdate/{{empSelect.id}}'"/>
</div><br><br>
<a href ="http://10.1.0.90:8080/filter/{{emp.id}} "> Back </a><br><br>
<a href ="http://10.1.0.90:8080/employeeList/ "> Home Page </a>
</body></html>
如果我提供的代碼有很多錯誤,請幫我糾正它。
那麼...又是什麼錯誤? – 2011-03-07 05:08:06
當我點擊員工個人資料頁面中的'返回'按鈕時,我無法獲取會話值。 – 2011-03-07 05:09:43
點擊後退按鈕不會重新加載頁面。 – 2011-03-07 05:10:57