I'm controlling the GPIO pins on a raspberryPi that is running a Django web 
app. I have a form with only one button that is "On" or "off", it writes 
this to a database. The Button's value has to display the current status 
"On" or"off".
So I need to be able to update the value of the button in the form, without 
reloading the entire page.

I have jquery, so I'm trying to figure out how to use it in conjunction 
with the Django View to get this done. Here is my View.py and 
control_page.html

I am a novice in Programming so don't be afraid to dumb it down....

@login_required
def control_page(request):
  if request.method == 'POST':   
    pin1 = Pin.objects.get(pinID=1)
    
    if 'pin1Status' in request.POST:
      if pin1.pinStatus == 'hi':
        pin1.pinStatus = 'low'
      else:
        pin1.pinStatus = 'hi'
      pin1.save()
      
    variables = RequestContext(request, {'pin1': pin1})      
    return render_to_response('control_page.html', variables)
  else:
    pin1 = Pin.objects.get(pinID=1)
    variables = RequestContext(request, {'pin1': pin1})
    return render_to_response('control_page.html', variables) 
    
    
    
        
{% extends "base.html" %}
{% block external %}
  <script type="text/javascript" src="/media/jquery.js"></script>
  <script type="text/javascript" src="/media/jquery_ui.js"></script> 
  <script type="text/javascript" src="/media/gpio.js"></script>
{% endblock %}
{% block title %}Control Panel{% endblock %}
{% block head %}

{% endblock %}
{% block content %}

  <div id="gpio_results">
  <form id="gpio_form" method="post" action="." >
    {% csrf_token %}
    <p>{{ pin1.pinDescription}} {{ pin1.pinDirection}}  
    <input type="submit" name="pin{{ pin1.pinID }}Status" id="{{ pin1.pinID 
}}" value="{{ pin1.pinStatus }}"   />
  </form>
  </div>
  
  <iframe src="http://192.168.137.96:8081"; scrolling="no" width="275" 
height="220" frameboarder="0">
    <p>iframes are not supported by your browser.<p>
  </iframe>
  
{% endblock %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to