rokpoto.com
rokpoto.com

Reputation: 10746

Use existing html page elements (its form and button) withing django app

My goal is to run python function when a user clicks on a button within a form on my web page, when the argument is taken from textarea HTML element. The following html code is my form with button within and is part of django application.

<div id="contact_form" class="col_400 float_l">
      <form id="demoForm"  name="contact" >  

         <label for="text">Your Review:</label>
         <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea>
         <div class="cleaner_h10"></div>

         <input type="button" onclick="return Button1_onclick()" class="submit_btn float_l" name="submit" id="predictSentBtn" value="Predict" />

      </form>
</div>

I looked on django.forms and django.forms.widgets, but still don't understand how to "link" between existing html elements and python objects.

Upvotes: 0

Views: 205

Answers (1)

Silwest
Silwest

Reputation: 1620

This should help:

<div id="contact_form" class="col_400 float_l">
  <form id="demoForm"  name="contact" >  

     <label for="text">Your Review:</label>
     <textarea id="needid" name="needid" rows="0" cols="0" class="required"></textarea>
     <div class="cleaner_h10"></div>

     <input type="button" onclick="return Button1_onclick()" class="submit_btn float_l" name="submit" id="predictSentBtn" value="Predict" />

  </form>

 def function(request):
    if request.method = 'POST':
        print request.POST['needid'] # print request.POST.get('needid')

Try it ;)

Upvotes: 1

Related Questions