在我的Django應用程序中,我想使用Twitter引導程序單選按鈕。然後我想發佈這些按鈕的值以創建一個對象。帶單選按鈕的jQuery post功能
這裏是我的按鈕:
<div class="btn-group" data-toggle="buttons-checkbox">
<button type="button" class="btn" name="supporting">Team1</button>
<button type="button" class="btn" name="supporting">Team2</button>
</div>
<div class="span6 btn-group ib" data-toggle="buttons-radio">
<button type="button" class="btn btn-primary active" name="style">relaxed</button>
<button type="button" class="btn btn-primary active" name="style">strict</button>
</div>
<input type="submit" value="create your match">
我想擺脫這些單選按鈕的信息,並在視圖中創建一個對象匹配:
def test(request):
user=request.user
if request.method == 'POST':
style = request.POST['style']
supporting = request.POST['supporting']
match = Match.objects.create(user=user, style=style, supporting=supporting)
return HttpResponse(test)
的事情是,我不太瞭解JavaScript,所以我沒有找到如何從按鈕獲取值。
然後,我想我必須使用:
$.post('/sportdub/points_dub/', {'style': style , 'supporting': supporting});
可是我該怎麼做,這樣的風格和配套對應按鈕的值,然後將它張貼僅當在用戶點擊按鈕?
非常感謝您的幫助。
所以......你爲什麼不使用我的代碼從其他答案?什麼問題?所有你需要做的就是'alignment = request.POST ['alignment']' – balexandre