我試圖添加使用django &'POST'方法提交的學生的詳細信息。 提交時,我將詳細信息保存在我的'py'文件中。之後,我想重定向到主頁。 早些時候我用在django中提交表單後重定向到帶有參數的主頁
return render_to_response("home.html",{ "edit":0,"msg":'saved'}, context_instance=RequestContext(request))
但在主頁的每個耳目一新,它將插入數據表。 然後我嘗試使用「HttpResponseRedirect」,但它不支持參數傳遞。 我該如何解決這個問題?
add.py
stud = student(name=request.POST['studname'])
stud.save()
return render_to_response("home.html",{ "edit":0,"msg":'saved'}, context_instance=RequestContext(request))
student.html
<form id = "addForm" name = "addForm" action = "" method = 'POST' >
<table>
<tr>
<td>Name.</td>
<td><input type="text" name="studname" id="studname"></td>
</tr>
</table>
</form>
化妝名同一主題的另一篇文章作爲unigue在Django模型 – 2014-10-10 09:05:53
=真當你得到你的答案時,將其標記爲已驗證。 – ancho 2014-10-10 11:08:53
但是不同學生的名字,班級等可以相同 – user123 2014-10-11 04:54:20