Skip to content

Instantly share code, notes, and snippets.

@jumbojet
Last active December 23, 2015 18:39
Show Gist options
  • Save jumbojet/6677454 to your computer and use it in GitHub Desktop.
Save jumbojet/6677454 to your computer and use it in GitHub Desktop.
sample view
def get_units(request):
# request object has one GET DICTIONARY for the variables passed as Query String
# Query string variable is named as ID
if 'ID' in request.GET:
userId = request.GET['ID']
# request object has one POST DICTIONARY for the variables passed as form.submit()
# Here assume a form variable is named as UNITS
if 'UNITS' in request.POST:
units = request.POST['UNITS']
readingData = get_units_data(userId)
output_json = jsonpickle.encode(readingData) #unpickled = jsonpickle.decode(output_json)
''' Here we are able to send JSON as htttp response. Comes in handy for API writting'''
return HttpResponse(output_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment