Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

How To: update dashboard in Django

cbrentharris edited this page Jul 15, 2014 · 2 revisions

This is an example of how to dynamically update a dashing widget from the django webframework

myproject/settings.py

...
DASHING_URL = 'http://localhost:3030/widgets' #replace with actual url
DASHING_AUTH_TOKEN = 'YOUR_AUTH_TOKEN' #replace with actual auth token

myapp/views.py

from myproject import settings
import json
import urllib2

def update_welcome(request):

    #we'll assume a text widget 
    widget = 'some_text_widget'
    widget_json = {}

    widget_json['title'] = request.POST['title']
    widget_json['text'] = request.POST['text']
    widget_json['auth_token'] = settings.DASHING_AUTH_TOKEN
    
    req = urllib.Request(settings.DASHING_URL + widget)
    response = urllib.urlopen(req, json.dumps(widget_json))
    if response:
        ...