2013-05-19 16 views
1

我在模板中有一個按鈕,當我點擊按鈕時它將創建一個對象。我是django的新手。什麼是使用按鈕的正確方法。Django我如何使用模板中的按鈕

<form action="" method="POST">{% csrf_token %} 
    <input type=submit name="submit"> 
    </form> 

意見

  def create_object(request): 
      if 'submit' in request.POST: 
                             Employee.object.create(emp_name='test',emp_email='[email protected]') 
      HttpResponse(" ") 
+0

你能更具體一點嗎?哪個對象/實例將被創建?它是否依賴於更多的POST數據而不僅僅是按下按鈕?它是否被保存到數據庫? – Jingo

回答

-1

試試這個

def create_object(request): 
    if 'submit' in request.POST: 
    #Employee.object.create(emp_name='test',emp_email='[email protected]')<--- just commented out 
button = "<button>your button</button>" 
return render_to_response('your.html',{'button':button},context_instance=RequestContext(request)) 

模板

{{button|safe}} <------------ will show your rendered button 

告訴我,如果你在理解這個代碼

問題
+0

它似乎不適合我,並沒有得到任何錯誤。當我點擊按鈕,我只是得到一個空白頁面 –

+0

@RobertGarcia,在網絡控制檯的錯誤是什麼? – doniyor

相關問題