Re: Need help in converting the key value pairs of JSON data into data types.

2021-08-11 Thread Kasper Laudrup
On 11/08/2021 21.20, Franck Tchouanga wrote:
> I can help you.
>

Help me with what?

Kind regards,

Kasper Laudrup

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/90dcdc26-d694-e3e0-1a1e-76178f953c40%40stacktrace.dk.


OpenPGP_signature
Description: OpenPGP digital signature


Re: Need help in converting the key value pairs of JSON data into data types.

2021-08-11 Thread Franck Tchouanga
I can help you.

On Wed, Aug 11, 2021, 6:00 PM Kasper Laudrup  wrote:

> On 11/08/2021 15.54, chinna wrote:
> > Hi All,
> >
> > I am actually working on a use case where I have to convert the JSON
> > data into a dictionary and from that  I will have to replace all the
> > keys and values to the data types.
>
> The data type is returned as a string with the builtin type() function.
>
> > For example:
> >
> > input_dict  = {'segment_idenifier': 'Segment 2',
> > 'exposed_pipe_outside_diam': 4, 'exposed_pipe_length': 2}
> >
> > output_dict = {string : string, string : integer, string : integer }
> >
> > in some cases the dictionary will have nested dictionaries or lists as
> > well. If it has, we will have to replace the key-values inside those
> > nested objects.
> >
>
> The JSON library included with the Python standard supports nested
> objects (converting them into Python dictionaries) just fine, so that
> shouldn't be an issue:
>
> https://docs.python.org/3/library/json.html
>
> > I am including the json file here.
> >
> > I was struck by this a while ago. Please help me to resolve this.
> >
>
> What have you done so far and where exactly are you facing issues?
>
> Also, how is this related to Django?
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a473aa95-8366-0834-1900-03946506b9bb%40stacktrace.dk
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANRJ%3D3kqR8DdkBANwNuRCCeT6j8jubsia-N-WjXHdbSj_-dSBA%40mail.gmail.com.


Re: Need help in converting the key value pairs of JSON data into data types.

2021-08-11 Thread Kasper Laudrup
On 11/08/2021 15.54, chinna wrote:
> Hi All,
> 
> I am actually working on a use case where I have to convert the JSON
> data into a dictionary and from that  I will have to replace all the
> keys and values to the data types. 

The data type is returned as a string with the builtin type() function.

> For example:
> 
> input_dict  = {'segment_idenifier': 'Segment 2',
> 'exposed_pipe_outside_diam': 4, 'exposed_pipe_length': 2}
> 
> output_dict = {string : string, string : integer, string : integer } 
> 
> in some cases the dictionary will have nested dictionaries or lists as
> well. If it has, we will have to replace the key-values inside those
> nested objects.
> 

The JSON library included with the Python standard supports nested
objects (converting them into Python dictionaries) just fine, so that
shouldn't be an issue:

https://docs.python.org/3/library/json.html

> I am including the json file here.
> 
> I was struck by this a while ago. Please help me to resolve this.
> 

What have you done so far and where exactly are you facing issues?

Also, how is this related to Django?

Kind regards,

Kasper Laudrup

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a473aa95-8366-0834-1900-03946506b9bb%40stacktrace.dk.


OpenPGP_signature
Description: OpenPGP digital signature


Need help in converting the key value pairs of JSON data into data types.

2021-08-11 Thread chinna
Hi All,

I am actually working on a use case where I have to convert the JSON data
into a dictionary and from that  I will have to replace all the keys and
values to the data types.
For example:

input_dict  = {'segment_idenifier': 'Segment 2',
'exposed_pipe_outside_diam': 4, 'exposed_pipe_length': 2}

output_dict = {string : string, string : integer, string : integer }

in some cases the dictionary will have nested dictionaries or lists as
well. If it has, we will have to replace the key-values inside those nested
objects.

I am including the json file here.

I was struck by this a while ago. Please help me to resolve this.

Regards,
Prem.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG%3DmdoCyUqpGTn55ToUrzO0op%3DWsyrYEybx7sv4k4SFrnd0AqA%40mail.gmail.com.


package.json
Description: application/json


How to parse JSON data in python and Django

2021-06-29 Thread Salima Begum
Hi all,

>From below json data to parse this data to fetch categoryId and
categoryName in four levels of data I used for loop for fetching data and
inserting into database table. Is there any better way to do this in python
and Django?

Please Help me to achieve this. Let me know if you have any suggestions.

```
response = requests.request("GET", url, headers=headers_name, data=payload)
response.json()
json_encoded_e = json.dumps(response.json(), indent=4)
json_decode_e = json.loads(json_encoded_e)
categoryTreeId = json_decode_e["categoryTreeId"]
categoryTreeVersion = json_decode_e["categoryTreeVersion"]
rootCategoryNode = json_decode_e["rootCategoryNode"]
json_encoded_e1 = json.dumps(rootCategoryNode, indent=4)
json_decode_e1 = json.loads(json_encoded_e1)
category_1 = json_decode_e1["childCategoryTreeNodes"]
for i in category_1:
cat_id = i['category']['categoryId']
cat_name = i['category']['categoryName']
category_child = i['childCategoryTreeNodes']
saveForm = Some_data_table(categoryTreeId=categoryTreeId,
categoryTreeVersion=categoryTreeVersion,
categoryId=cat_id,
categoryName=cat_name,
parent_id=cat_id, parent_name=cat_name,
)
saveForm.save()
for child in category_child:
cat_ch_id = child['category']['categoryId']
cat_ch_name = child['category']['categoryName']
saveForm = Some_data_table(categoryTreeId=categoryTreeId,

categoryTreeVersion=categoryTreeVersion,
categoryId=cat_ch_id,
categoryName=cat_ch_name,
parent_id=cat_id,
parent_name=cat_name,
)
saveForm.save()
if 'childCategoryTreeNodes' in child:
cat_subch= child['childCategoryTreeNodes']
for subch in cat_subch:
cat_subch_id = subch['category']['categoryId']
cat_subch_name = subch['category']['categoryName']
saveForm =
Some_data_table(categoryTreeId=categoryTreeId,

categoryTreeVersion=categoryTreeVersion,
categoryId=cat_subch_id,
categoryName=cat_subch_name,
parent_id=cat_ch_id,
parent_name=cat_ch_name,
)
saveForm.save()
if 'childCategoryTreeNodes' in subch:
cat_subch_subch = subch['childCategoryTreeNodes']
for subch_subch in cat_subch_subch:
cat_subch_subch_id =
subch_subch['category']['categoryId']
cat_subch_subch_name =
subch_subch['category']['categoryName']
saveForm =
Some_data_table(categoryTreeId=categoryTreeId,

categoryTreeVersion=categoryTreeVersion,

categoryId=cat_subch_subch_id,

categoryName=cat_subch_subch_name,

parent_id=cat_subch_id, parent_name=cat_subch_name,
)
saveForm.save()

else:
continue
else:
continue

```

```
{'categoryTreeId': '0',
 'categoryTreeVersion': 'some',
 'rootCategoryNode': {'category': {'categoryId': '0', 'categoryName':
'Root'},
 'childCategoryTreeNodes':
 [{'category': {'categoryId': '1', 'categoryName': 'Collectibles'},
'parentCategoryTreeNodeHref': 'https://api.example.com/',
'childCategoryTreeNodes':
[{'category': {'categoryId': '34', 'categoryName': 'Advertising'},
'parentCategoryTreeNodeHref': 'https://api.example.com/category_id=1',
'childCategoryTreeNodes':
[{'category': {'categoryId': '36', 'categoryName': 'Soda'},
'parentCategoryTreeNodeHref': 'https://api.example.com/category_id=34',
'childCategoryTreeNodes':
[{'category': {'categoryId': '852', 'categoryName': 'Fountain'},
'parentCategoryTreeNodeHref': 'https://api.example.com/category_id=36',
'categoryTreeNodeLevel': 4, 'leafCategoryTreeNode': True},
{'category': {'categoryId': '853', 'categoryName': 'Canada Dry'},
'parentCategoryTreeNodeHref': 'https://api.example.com/category_id=36',
'categoryTreeNodeLevel': 4, 'leafCategoryTreeNode': True},
{'category': {'categoryId': '855', 'categoryName': '7 UP'},
'parentCategoryTreeNodeHref': 'https://api.example.com/category_id=36',
'categoryTreeNodeLevel': 4, 'leafCategoryTreeNode': True},
{'category': {'categoryId': '856', 'categoryName': 'Squirt'},
'parentCategoryTreeNodeHref': 'https://api.example.com/category_id=36',
'categoryTreeNodeLevel': 4, 'leafCategoryTreeNode': True},
{'category': {'categoryId': '857', 'categoryName': 'Hires Root Beer'},
'parentCategoryTreeNodeHref': 'https://api.ex

Re: JSON data

2020-05-24 Thread Saurabh Adhikary
data =  [{"exped": "MA", "destin": "AL", "count": 2}, {"exped": "MA", 
"destin": "BS", "count": 1}] 
mylist = []
for a in data :
mylist.append([a['exped'],a['destin'],a['count']])



On Sunday, 24 May 2020 17:16:46 UTC+5:30, HJ wrote:
>
> hello guys hope you are doing well 
>
> I am trying to make a highchart but I found a problem in the view function 
> so my chart doesn't show becuase of that 
>
> view function 
>
> def jsonDepend(request):
>  dataset = mail_item_countries_depend.objects.all().values('exped',
> 'destin','count')
>  data = list(dataset)
>
>   return JsonResponse(data, safe=False)
>
>
> my views function show something like this : [{"exped": "MA", "destin": 
> "AL", "count": 2}, {"exped": "MA", "destin": "BS", "count": 1}]  
>
> how can I store it like that : [["MA", "AL",  2], ["MA", "BS", 1]] 
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0a644423-e96c-46d5-9f3e-c9dd3195f189%40googlegroups.com.


JSON data

2020-05-24 Thread HJ
hello guys hope you are doing well 

I am trying to make a highchart but I found a problem in the view function 
so my chart doesn't show becuase of that 

view function 

def jsonDepend(request):
 dataset = mail_item_countries_depend.objects.all().values('exped','destin',
'count')
 data = list(dataset)

  return JsonResponse(data, safe=False)


my views function show something like this : [{"exped": "MA", "destin": 
"AL", "count": 2}, {"exped": "MA", "destin": "BS", "count": 1}]  

how can I store it like that : [["MA", "AL",  2], ["MA", "BS", 1]] 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/724f6ea8-87fe-42f2-bfac-d44c70cd30b9%40googlegroups.com.


Re: How To Send Json data To Django

2020-03-16 Thread Harsh Tibrewal
if you send the code snippet i can help 

On Friday, March 13, 2020 at 9:27:28 PM UTC+5:30, venna venkatReddy wrote:
>
> Hi i am learing django, so i decided to do one small project on django is 
> that Exam type website.
>
> I Need Help, Regrading How To Send Json data To Django  
>
> when i entering the question and answers from fronend. I successfult 
> stored on Local Storage in json formate, But Once click on clikc on submit 
> buten its need to send to backend models, 
>
> How to send to that json local storaga json data to bakend 
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b547079c-2886-4540-84d6-ada4d9982951%40googlegroups.com.


Re: How To Send Json data To Django

2020-03-14 Thread jitendra yadav
hi deepak
 Read your json file from local storage or from api   in python view and
save in model using ORM in django

On Sat, Mar 14, 2020 at 8:53 AM Desh Deepak  wrote:

> Hi,
>
> Go to the below link:
> https://youtu.be/9N6a-VLBa2I
>
>
> Thanks & regards
> Desh Deepak
> +91 7011101001
>
> On Fri, 13 Mar 2020 at 9:26 PM, venna venkatReddy <
> vennavenkat...@gmail.com> wrote:
>
>> Hi i am learing django, so i decided to do one small project on django is
>> that Exam type website.
>>
>> I Need Help, Regrading How To Send Json data To Django
>>
>> when i entering the question and answers from fronend. I successfult
>> stored on Local Storage in json formate, But Once click on clikc on submit
>> buten its need to send to backend models,
>>
>> How to send to that json local storaga json data to bakend
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/7fd58db8-966a-402f-9428-f7623581d0a4%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/7fd58db8-966a-402f-9428-f7623581d0a4%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJ0m4xhs8HLdMB6j_do%2BSUbcMsfHzOV_6MD6g59fAXa4necm2A%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAJ0m4xhs8HLdMB6j_do%2BSUbcMsfHzOV_6MD6g59fAXa4necm2A%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO85EQPjXV2VkwSLVUaBiReweg9X8qATZKumwdT4R8Pj%2Brweqw%40mail.gmail.com.


Re: How To Send Json data To Django

2020-03-13 Thread Desh Deepak
Hi,

Go to the below link:
https://youtu.be/9N6a-VLBa2I


Thanks & regards
Desh Deepak
+91 7011101001

On Fri, 13 Mar 2020 at 9:26 PM, venna venkatReddy 
wrote:

> Hi i am learing django, so i decided to do one small project on django is
> that Exam type website.
>
> I Need Help, Regrading How To Send Json data To Django
>
> when i entering the question and answers from fronend. I successfult
> stored on Local Storage in json formate, But Once click on clikc on submit
> buten its need to send to backend models,
>
> How to send to that json local storaga json data to bakend
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7fd58db8-966a-402f-9428-f7623581d0a4%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/7fd58db8-966a-402f-9428-f7623581d0a4%40googlegroups.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJ0m4xhs8HLdMB6j_do%2BSUbcMsfHzOV_6MD6g59fAXa4necm2A%40mail.gmail.com.


How To Send Json data To Django

2020-03-13 Thread venna venkatReddy
Hi i am learing django, so i decided to do one small project on django is 
that Exam type website.

I Need Help, Regrading How To Send Json data To Django  

when i entering the question and answers from fronend. I successfult stored 
on Local Storage in json formate, But Once click on clikc on submit buten 
its need to send to backend models, 

How to send to that json local storaga json data to bakend 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7fd58db8-966a-402f-9428-f7623581d0a4%40googlegroups.com.


Re: Sending json data to postgres once received from API

2020-02-13 Thread Ilya Rustamov
Thank you Jody, I will take a look at this and see how it goes.

On Thursday, February 13, 2020 at 3:27:03 PM UTC-5, Jody Fitzpatrick wrote:
>
> Hello Ilya
>
> I would read the following:
>
> https://docs.djangoproject.com/en/3.0/topics/db/models/
>
> Essentially, what you do in shell is what you would do in your code. 
>
> I also believe you might want to look at how you are grabbing the posted 
> data.
>
> I would use something like url = request.GET.get('url', False)
>
> So you want break your code and can validate if it was indeed sent. 
>
> Best of luck
>
> ps.
>
> Also, look at postgres models.JsonField
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2142e140-794f-4447-ba5e-8f7e69fa11ab%40googlegroups.com.


Re: Sending json data to postgres once received from API

2020-02-13 Thread Jody Fitzpatrick
Hello Ilya

I would read the following:

https://docs.djangoproject.com/en/3.0/topics/db/models/

Essentially, what you do in shell is what you would do in your code. 

I also believe you might want to look at how you are grabbing the posted 
data.

I would use something like url = request.GET.get('url', False)

So you want break your code and can validate if it was indeed sent. 

Best of luck

ps.

Also, look at postgres models.JsonField

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b85cc4ac-54eb-47bb-b78e-2364363f28d6%40googlegroups.com.


Sending json data to postgres once received from API

2020-02-13 Thread Ilya Rustamov
Hey Devs,

   First time poster here, if I am missing anything or am not following 
general rules and practices feel free to let me know.

I am in the process of building an app that asks user for a url and on 
submit makes post request to said url, receives json data and simply prints 
it in a new view.

This part of the app works well and does the job it is supposed to do, my 
only issue is that once the app has received that data, not only do I want 
it printed but would also like for it to be entered into a table in my 
postgres db. 

I have already connected a postgres db and it has a table that is built 
from my models that can receive this data.

I am struggling to understand how to actually send data to the db from the 
app, the only understanding I have of entering data into db is using the 
shell which does not solve my issue. 

My goal is to be able to save the json data i receive from the url into 
that table in my postgres db? What is the best and most efficient way to go 
about accomplishing this?

I will attach some of my code so you can see what I am working with so far.


views.py 

from django.shortcuts import HttpResponse, render
import urllib.request
import json


def home(request):
return render(request, 'djangoAPI/response.html')


def result(request):
url = request.GET['url']
operUrl = urllib.request.urlopen(url)
if operUrl.getcode() == 200:
data = operUrl.read()
jsonData = json.loads(data)
final = json.dumps(jsonData, indent=2, sort_keys=True)
else:
print("Error receiving data", operUrl.getcode())

return render(request, 'djangoAPI/request.html', {'result': final})




models.py

from django.db import models


class URLData(models.Model):
id  = models.IntegerField(primary_key=True)
title   = models.CharField(max_length=200)
summary = models.TextField()
description = models.TextField()
url = models.URLField(max_length=200)
rssFeed = models.TextField(blank=True, null=True)
links   = models.TextField(blank=True, null=True)

def __str__(self):
return self.title



-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/67f33d50-3dca-4391-a54e-ec420d833912%40googlegroups.com.


Re: How to create model for this json data

2019-02-20 Thread 'Amitesh Sahay' via Django users
Hi,
First, try to understand the error messages. It says there are fields that are 
required, but you are leaving them blank. Then, there are some fields those 
cannot have "null", but soemhow you are adding null values to them.
I would suggest using below Django CLI commands to add the data to your table
python manage.py loaddata .
Below is the link that will guide you with further informationDjango dumpdata 
and loaddata (Example)


| 
| 
| 
|  |  |

 |

 |
| 
|  | 
Django dumpdata and loaddata (Example)

A protip by itseranga about django, database, model, and dumpdata.
 |

 |

 |


I hope that will come handy to you.
Regards,
Amitesh Sahay91-750 797 8619 

On Wednesday, 20 February, 2019, 12:31:23 pm IST,  
wrote:  
 
 

On Tuesday, February 19, 2019 at 10:02:32 PM UTC+5:30, optvi...@gmail.com wrote:
Hi I have data like this
{
"Name" : "pk",
"Applist" : ["zom","bc"],
 "Url":   ["As","de"]

}

How to define field name for list I am not getting

i define a class with foreign key but still getting error?

class keywordfield(models.Model):
keyword=models.CharField(max_length=50,null=True)
appNamefield=models.ForeignKey("appNamefield", on_delete=models.CASCADE)






class appNamefield(models.Model):
appName = models.CharField(max_length=50,null=True)


serializer class
class appDetailsSearilizer(serializers.ModelSerializer):
    class Meta:
model = keywordfield


fields = ('id','keyword','appNamefield')

json data

{
  
"keyword": "food",
  "appNamefield":["j","l"]

  
}


error
dict_items([('required', 'This field is required.'), ('null', 'This field may 
not be null.'), ('invalid', 'Invalid data. Expected a dictionary, but got 
{datatype}.')])
 



 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/914062e6-1475-4653-8010-58a43b5bacb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1172024440.2200567.1550650685702%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to create model for this json data

2019-02-19 Thread optvisitor


On Tuesday, February 19, 2019 at 10:02:32 PM UTC+5:30, optvi...@gmail.com 
wrote:
>
> Hi I have data like this 
> { 
> "Name" : "pk", 
> "Applist" : ["zom","bc"], 
>  "Url":   ["As","de"] 
>
> } 
>
> How to define field name for list I am not getting


i define a class with foreign key but still getting error?

class keywordfield(models.Model):
keyword=models.CharField(max_length=50,null=True)
appNamefield=models.ForeignKey("appNamefield", on_delete=models.CASCADE)






class appNamefield(models.Model):
appName = models.CharField(max_length=50,null=True)


serializer class
class appDetailsSearilizer(serializers.ModelSerializer):
class Meta:
model = keywordfield


fields = ('id','keyword','appNamefield')

json data

{
  
"keyword": "food",
  "appNamefield":["j","l"]

  
}


error
dict_items([('required', 'This field is required.'), ('null', 'This field may 
not be null.'), ('invalid', 'Invalid data. Expected a dictionary, but got 
{datatype}.')])

 




 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/914062e6-1475-4653-8010-58a43b5bacb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: How to create model for this json data

2019-02-19 Thread Matthew Pava
You can use ForeignKey.
Or ArrayField if you're using PostgreSQL as your backend.

https://docs.djangoproject.com/en/2.1/ref/contrib/postgres/fields/#arrayfield


-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of optvisi...@gmail.com
Sent: Tuesday, February 19, 2019 10:02 AM
To: Django users
Subject: How to create model for this json data

Hi I have data like this
{
"Name" : "pk",
"Applist" : ["zom","bc"],
 "Url":   ["As","de"]

}

How to define field name for list I am not getting

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1dbdd1f4-6d19-4cc7-828b-e360395edf6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b5f32b6b7e4643d19fdb30c83b8bb229%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


How to create model for this json data

2019-02-19 Thread optvisitor
Hi I have data like this
{
"Name" : "pk",
"Applist" : ["zom","bc"],
 "Url":   ["As","de"]

}

How to define field name for list I am not getting

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1dbdd1f4-6d19-4cc7-828b-e360395edf6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: serializers.serialize('json', data) return text

2019-02-12 Thread Jason
Check out JSONResponse 


-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c7580fdd-dc78-4857-9359-164c28794154%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


serializers.serialize('json', data) return text

2019-02-12 Thread Yossef Vecsler
hi,

i am using:
"serializers.serialize('json', data)"
to make a json (i also use json.dumps in other cases).

how can i make "serializers.serialize('json', data)" to return json to the 
js?
because now i must make:
ans = the ajax returns -> "serializers.serialize('json', data)"
JSON.parse(ans)

while when using json.dumps its straight forward with no parsing the data...

thanks

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c467c1a3-63d7-4b29-a3b7-a64eabd8b088%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Convert JSON data into structured data in an SQL database using Django ORM

2019-02-02 Thread Mark Phillips
MySQL and Postgres both support JSON fields directly, and have some
searching capability built in for those fields. I don't think you have to
use the django-jsonfield anymore. Check the

MySQL and/or Postgres docs -
https://dev.mysql.com/doc/refman/8.0/en/json.html
https://www.postgresql.org/docs/9.3/functions-json.html

JSON, Django, and MySQL docs
https://django-mysql.readthedocs.io/en/latest/installation.html

Mark

Mark

On Sat, Feb 2, 2019 at 2:04 PM Parth Sharma 
wrote:

> I am building a chatbot using Django with a MySQL backend.
> I have a `ChatSession` model which represents all the useful information
> to be stored after the end of a chat session .
>
> Now, it has a JSON field called `cc_data`(Implemented using
> [`django-jsonfield`](https://github.com/dmkoch/django-jsonfield))
>
> Here's an example of the content of that field:
> ```
> {
>   "slots":{
> "chal_tech":"What is the Proof",
> "nats":["I will fail the course","Nobody likes me"],
> "distortion":"Jumping to Conclusions",
> "user_name":"parth",
>   }
> }
> ```
> I recently realized that I need to query for some fields in this `slots`
> dictionary. An example query would be to list out all the `nats` in the
> last 10 chat sessions.
>
> It seems that reading all the values of the JSONs into dicts and then
> searching/manipulating them would be inefficient.Therefore I sought to
> convert this JSON representation into Django ORM models(SQL).
>
> However, while trying to do this I ran into a problem. The "keys" of the
> `slots` dictionary are probably finite in number, but I don't know exactly
> how many of them will be required at this point. In any case, it would be a
> large number (around 50-100).
>
> - Manually writing the model classes for so many attributes in `models.py`
> seems inefficient and also a bit repetitive (Most of them would simply have
> a single `JSONfield` or `TextField`). Even with abstract models I would
> still have to list out classes for all the "keys" in the `models.py` file.
> - Ideally I'd like to generate model classes for any new "keys"
> automatically and on the fly. I did look at [dynamic models in Django](
> https://stackoverflow.com/questions/7933596/django-dynamic-model-fields/7934577#7934577)
> but none of the solutions really seem efficient. The host I am using
> doesn't support NoSQL so I can't use that solution.
>
>
> How do I convert this into valid a valid Django ORM/SQL design so that the
> queries are efficient and the code isn't repetitive ?
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/1bfeb786-9675-45e6-98df-9471ce5391dc%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEqej2OMHrzx%3DKxGG%3DwYQ50JZ6KfeLA%3DfhF9oZzi8BWPqnqoTQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Convert JSON data into structured data in an SQL database using Django ORM

2019-02-02 Thread Parth Sharma
I am building a chatbot using Django with a MySQL backend. 
I have a `ChatSession` model which represents all the useful information to 
be stored after the end of a chat session . 

Now, it has a JSON field called `cc_data`(Implemented using 
[`django-jsonfield`](https://github.com/dmkoch/django-jsonfield))

Here's an example of the content of that field:
```
{
  "slots":{
"chal_tech":"What is the Proof",
"nats":["I will fail the course","Nobody likes me"],
"distortion":"Jumping to Conclusions",
"user_name":"parth",
  }
}
```
I recently realized that I need to query for some fields in this `slots` 
dictionary. An example query would be to list out all the `nats` in the 
last 10 chat sessions. 

It seems that reading all the values of the JSONs into dicts and then 
searching/manipulating them would be inefficient.Therefore I sought to 
convert this JSON representation into Django ORM models(SQL). 

However, while trying to do this I ran into a problem. The "keys" of the 
`slots` dictionary are probably finite in number, but I don't know exactly 
how many of them will be required at this point. In any case, it would be a 
large number (around 50-100).

- Manually writing the model classes for so many attributes in `models.py` 
seems inefficient and also a bit repetitive (Most of them would simply have 
a single `JSONfield` or `TextField`). Even with abstract models I would 
still have to list out classes for all the "keys" in the `models.py` file.
- Ideally I'd like to generate model classes for any new "keys" 
automatically and on the fly. I did look at [dynamic models in 
Django](https://stackoverflow.com/questions/7933596/django-dynamic-model-fields/7934577#7934577)
 
but none of the solutions really seem efficient. The host I am using 
doesn't support NoSQL so I can't use that solution.


How do I convert this into valid a valid Django ORM/SQL design so that the 
queries are efficient and the code isn't repetitive ?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1bfeb786-9675-45e6-98df-9471ce5391dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Saving Json data from javascript

2018-02-13 Thread Etienne Robillard
I'm not really sure what you meant here. Anyways, there's plenty of good 
JS frameworks like jQuery to allow you to write Ajax functions to send a 
JSON array for post-processing in Django.


Etienne

Le 2018-02-13 à 08:34, Shazia Nusrat a écrit :
Can you please show me any example about the structure of code I've 
provided?


Thanks

On Tue, Feb 13, 2018 at 2:27 AM, Etienne Robillard > wrote:


Hi Shazia,

You can make a XHR (Ajax) request in javascript to send the data
to a django callback.

HTH,

Etienne


Le 2018-02-12 à 18:04, Shazia Nusrat a écrit :

Hi,

Below is the code for Javascript from Django template Google Maps
API. I need to be able to save this in my Django models with JSON
response. I am new user so an example will be really a great help.

Precisely I need to be able to save coordinates like latitude and
longitude and then convert it to an address.

Thanks
varmap,infoWindow;functioninitMap(){        map
=newgoogle.maps.Map(document.getElementById('map'),{         
center:{lat:-34.397,lng:150.644},          zoom:6});       
infoWindow =newgoogle.maps.InfoWindow;// Try HTML5
geolocation.if(navigator.geolocation){         
navigator.geolocation.getCurrentPosition(function(position){varpos
={              lat:position.coords.latitude,             
lng:position.coords.longitude };           
infoWindow.setPosition(pos);           
infoWindow.setContent('Location found.');           
infoWindow.open(map);           
map.setCenter(pos);},function(){           
handleLocationError(true,infoWindow,map.getCenter());});}else{//
Browser doesn't support Geolocation         

handleLocationError(false,infoWindow,map.getCenter());}}functionhandleLocationError(browserHasGeolocation,infoWindow,pos){
 
      infoWindow.setPosition(pos);       
infoWindow.setContent(browserHasGeolocation ?'Error: The
Geolocation service failed.':'Error: Your browser doesn\'t
support geolocation.');        infoWindow.open(map);}

-- 
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 https://groups.google.com/group/django-users
.
To view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/CAD83tOzabkiPgniqofN6BH2tLogeiGE9JaZ5rppi3f44Hb0ybA%40mail.gmail.com

.
For more options, visit https://groups.google.com/d/optout
.


-- 
Etienne Robillard

tkad...@yandex.com 
https://www.isotopesoftware.ca/ 




--
Etienne Robillard
tkad...@yandex.com
https://www.isotopesoftware.ca/

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/42a3efaf-7a67-b436-d297-be9d3dfcdad7%40yandex.com.
For more options, visit https://groups.google.com/d/optout.


Re: Saving Json data from javascript

2018-02-13 Thread Shazia Nusrat
Can you please show me any example about the structure of code I've
provided?

Thanks

On Tue, Feb 13, 2018 at 2:27 AM, Etienne Robillard 
wrote:

> Hi Shazia,
>
> You can make a XHR (Ajax) request in javascript to send the data to a
> django callback.
>
> HTH,
>
> Etienne
>
> Le 2018-02-12 à 18:04, Shazia Nusrat a écrit :
>
> Hi,
>
> Below is the code for Javascript from Django template Google Maps API. I
> need to be able to save this in my Django models with JSON response. I am
> new user so an example will be really a great help.
>
> Precisely I need to be able to save coordinates like latitude and
> longitude and then convert it to an address.
>
> Thanks
>
> var map, infoWindow;
>   function initMap() {
> map = new google.maps.Map(document.getElementById('map'), {
>   center: {lat: -34.397, lng: 150.644},
>   zoom: 6
> });
> infoWindow = new google.maps.InfoWindow;
>
> // Try HTML5 geolocation.
> if (navigator.geolocation) {
>   navigator.geolocation.getCurrentPosition(function(position) {
> var pos = {
>   lat: position.coords.latitude,
>   lng: position.coords.longitude
> };
>
> infoWindow.setPosition(pos);
> infoWindow.setContent('Location found.');
> infoWindow.open(map);
> map.setCenter(pos);
>   }, function() {
> handleLocationError(true, infoWindow, map.getCenter());
>   });
> } else {
>   // Browser doesn't support Geolocation
>   handleLocationError(false, infoWindow, map.getCenter());
> }
>   }
>
>   function handleLocationError(browserHasGeolocation, infoWindow, pos) {
> infoWindow.setPosition(pos);
> infoWindow.setContent(browserHasGeolocation ?
>   'Error: The Geolocation service failed.' :
>   'Error: Your browser doesn\'t support 
> geolocation.');
> infoWindow.open(map);
>   }
>
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CAD83tOzabkiPgniqofN6BH2tLogei
> GE9JaZ5rppi3f44Hb0ybA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Etienne Robillardtkadm30@yandex.comhttps://www.isotopesoftware.ca/
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD83tOyZn16gV7%3D2am9W8je-Q4mQALNNR5TAgPwYvVs%2B_n%2B9aQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Saving Json data from javascript

2018-02-13 Thread Etienne Robillard

Hi Shazia,

You can make a XHR (Ajax) request in javascript to send the data to a 
django callback.


HTH,

Etienne


Le 2018-02-12 à 18:04, Shazia Nusrat a écrit :

Hi,

Below is the code for Javascript from Django template Google Maps API. 
I need to be able to save this in my Django models with JSON response. 
I am new user so an example will be really a great help.


Precisely I need to be able to save coordinates like latitude and 
longitude and then convert it to an address.


Thanks
varmap,infoWindow;functioninitMap(){        map 
=newgoogle.maps.Map(document.getElementById('map'),{          
center:{lat:-34.397,lng:150.644},          zoom:6});        infoWindow 
=newgoogle.maps.InfoWindow;// Try HTML5 
geolocation.if(navigator.geolocation){          
navigator.geolocation.getCurrentPosition(function(position){varpos ={  
            lat:position.coords.latitude,              
lng:position.coords.longitude };            
infoWindow.setPosition(pos);            
infoWindow.setContent('Location found.');            
infoWindow.open(map);            map.setCenter(pos);},function(){      
      handleLocationError(true,infoWindow,map.getCenter());});}else{// 
Browser doesn't support Geolocation          
handleLocationError(false,infoWindow,map.getCenter());}}functionhandleLocationError(browserHasGeolocation,infoWindow,pos){  
      infoWindow.setPosition(pos);        
infoWindow.setContent(browserHasGeolocation ?'Error: The Geolocation 
service failed.':'Error: Your browser doesn\'t support 
geolocation.');        infoWindow.open(map);}


--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD83tOzabkiPgniqofN6BH2tLogeiGE9JaZ5rppi3f44Hb0ybA%40mail.gmail.com 
.

For more options, visit https://groups.google.com/d/optout.


--
Etienne Robillard
tkad...@yandex.com
https://www.isotopesoftware.ca/

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e87c4a18-519e-5264-00cb-65d3203048bd%40yandex.com.
For more options, visit https://groups.google.com/d/optout.


Saving Json data from javascript

2018-02-12 Thread Shazia Nusrat
Hi,

Below is the code for Javascript from Django template Google Maps API. I
need to be able to save this in my Django models with JSON response. I am
new user so an example will be really a great help.

Precisely I need to be able to save coordinates like latitude and longitude
and then convert it to an address.

Thanks

var map, infoWindow;
  function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
  center: {lat: -34.397, lng: 150.644},
  zoom: 6
});
infoWindow = new google.maps.InfoWindow;

// Try HTML5 geolocation.
if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
  lat: position.coords.latitude,
  lng: position.coords.longitude
};

infoWindow.setPosition(pos);
infoWindow.setContent('Location found.');
infoWindow.open(map);
map.setCenter(pos);
  }, function() {
handleLocationError(true, infoWindow, map.getCenter());
  });
} else {
  // Browser doesn't support Geolocation
  handleLocationError(false, infoWindow, map.getCenter());
}
  }

  function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
  'Error: The Geolocation service failed.' :
  'Error: Your browser doesn\'t support
geolocation.');
infoWindow.open(map);
  }

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD83tOzabkiPgniqofN6BH2tLogeiGE9JaZ5rppi3f44Hb0ybA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to display JSON data in template

2016-06-27 Thread Stephen J. Butler
Your json_obj is just a collection of python data structures (dictionaries,
arrays, strings, ints, etc)... it isn't JSON. You need to serialize it to a
string first using DjangoJSONEncoder.

https://docs.djangoproject.com/en/1.9/topics/serialization/

On Mon, Jun 27, 2016 at 12:41 PM, <aysha...@gmail.com> wrote:

> Greetings,
>
> How can I access and display JSON data in a template html file? I am
> getting the JSON data back in the javascript console as follows :
>
> I tried {{ jason_data }} but no luck.
>
> Thank you!
>
> Here is how I am returning the json data in views.py:
>
> return HttpResponse(json_obj, content_type='application/json')
>
>
>1.
>2. Console:
>3. [Object, Object, Object, Object, Object, Object, Object, Object,
>Object, Object, Object, Object, Object, Object]
>   1. 0:Object
>   2. 1:Object
>   3. 2:Object
>   4. 3:Object
>   5. 4:Object
>   6. 5:Object
>   7. 6:Object
>   8. 7:Object
>   9. 8:Object
>   10. 9:Object
>   11. 10:Object
>   12. 11:Object
>   13. 12:Object
>   14. 13:Object
>   15. length:14
>   16. __proto__:Array[0]
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5742de2f-67d8-4553-bb78-25b6a9dbf9a0%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5742de2f-67d8-4553-bb78-25b6a9dbf9a0%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAD4ANxUYmWLg%3DgsGrCGM0eq7js-f2SM2cF3DgApHN%2BwpLCyssw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


how to display JSON data in template

2016-06-27 Thread ayshalab
Greetings,

How can I access and display JSON data in a template html file? I am 
getting the JSON data back in the javascript console as follows : 

I tried {{ jason_data }} but no luck.

Thank you!

Here is how I am returning the json data in views.py:

return HttpResponse(json_obj, content_type='application/json')


   1. 
   2. Console: 
   3. [Object, Object, Object, Object, Object, Object, Object, Object, 
   Object, Object, Object, Object, Object, Object]
  1. 0:Object
  2. 1:Object
  3. 2:Object
  4. 3:Object
  5. 4:Object
  6. 5:Object
  7. 6:Object
  8. 7:Object
  9. 8:Object
  10. 9:Object
  11. 10:Object
  12. 11:Object
  13. 12:Object
  14. 13:Object
  15. length:14
  16. __proto__:Array[0]
   

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5742de2f-67d8-4553-bb78-25b6a9dbf9a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: push yahoo finance json data into database

2015-06-09 Thread Oscar Buijten
Oh, here's a part of the model that I forgot to include.

class MyichiHistoricalData(models.Model):
id = models.IntegerField(db_column='ID', primary_key=True)  # Field 
name made lowercase.
symbol = models.CharField(max_length=10, blank=True, null=True)
exchange = models.CharField(max_length=10, blank=True, null=True)
yahoo_symbol = models.CharField(max_length=15)
symbol_period = models.IntegerField()
timeframe = models.CharField(max_length=10, blank=True, null=True)
date = models.DateField(blank=True, null=True)
updated = models.DateTimeField()
open = models.DecimalField(max_digits=10, decimal_places=4, blank=True, 
null=True)
high = models.DecimalField(max_digits=10, decimal_places=4, blank=True, 
null=True)
low = models.DecimalField(max_digits=10, decimal_places=4, blank=True, 
null=True)
close = models.DecimalField(max_digits=10, decimal_places=4, 
blank=True, null=True)
volume = models.IntegerField(blank=True, null=True)
average_volume = models.IntegerField(blank=True, null=True)

Le lundi 8 juin 2015 22:09:05 UTC+2, Oscar Buijten a écrit :
>
> Hi there,
> The python learning curve seems to be steeper than expected :-(
> As yesterday, help converting my php app into python/django will be 
> appreciated.
>
> I have the following:
>
>   snip  ---
> from django.core.management.base import BaseCommand, CommandError
> import json
> from collections import OrderedDict
> from yahoo_finance import Share 
> from data.models import MyichiTickers, MyichiHistoricalData
>
> exchange  = 'AMS'
> startdate = '2014-04-25'
> enddate   = '2014-04-29'
> minimum_avg_daily_volume = '10'
>
> class Command(BaseCommand):
> def handle(self, *args, **options):
> from yahoo_finance import Share 
> from data.models import MyichiTickers
> tickers_for_exchange = MyichiTickers.objects.filter(exchange=exchange)[:2]
> if tickers_for_exchange:
> for tickerlist in tickers_for_exchange:
> ticker = Share(tickerlist.ticker) 
> if ticker.get_avg_daily_volume() > minimum_avg_daily_volume:
> data = json.dumps(ticker.get_historical(startdate, enddate))
> data = json.loads(data)
> print data
>
>   snip  ---
>
> It may not be perfect, but it works.
> I would need to get 'data' into the 'MyichiHistoricalData' model
>
> The output is like this;
>   snip  ---
> [{u'High': u'6.565', u'Symbol': u'AGN.AS', u'Adj_Close': u'6.31564', 
> u'Volume': u'4376000', u'Low': u'6.428', u'Date': u'2014-04-29', u'Close': 
> u'6.551', u'Open': u'6.435'}, {u'High': u'6.479', u'Symbol': u'AGN.AS', 
> u'Adj_Close': u'6.18742', u'Volume': u'3163200', u'Low': u'6.38', u'Date': 
> u'2014-04-28', u'Close': u'6.418', u'Open': u'6.428'}, {u'High': u'6.535', 
> u'Symbol': u'AGN.AS', u'Adj_Close': u'6.18259', u'Volume': u'4780100', 
> u'Low': u'6.379', u'Date': u'2014-04-25', u'Close': u'6.413', u'Open': 
> u'6.529'}]
> [{u'High': u'13.94', u'Symbol': u'AH.AS', u'Adj_Close': u'13.57496', 
> u'Volume': u'2706600', u'Low': u'13.70', u'Date': u'2014-04-29', u'Close': 
> u'13.92', u'Open': u'13.70'}, {u'High': u'13.735', u'Symbol': u'AH.AS', 
> u'Adj_Close': u'13.34091', u'Volume': u'2784700', u'Low': u'13.56', 
> u'Date': u'2014-04-28', u'Close': u'13.68', u'Open': u'13.565'}, {u'High': 
> u'13.675', u'Symbol': u'AH.AS', u'Adj_Close': u'13.23364', u'Volume': 
> u'3012500', u'Low': u'13.44', u'Date': u'2014-04-25', u'Close': u'13.57', 
> u'Open': u'13.545'}]
>   snip  ---
>
> Where I need help it so extract the keys and values and give them the 
> correct model field names in order to save them.
>
> It should be easy really, bt several hours of readin, searching, trial & 
> error haven't given me the trick yet
>
> Any suggestions?
>
> Thanks!
>
> Oscar
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/583b73b4-244f-4a14-95c6-eca2e81ff9ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: push yahoo finance json data into database

2015-06-09 Thread Oscar Buijten
Hi James,
Thanks for such a detailed response. I looked at all your links (and 
already had come across some of them)
I guess that my question wasn't specific enough :-(

The table (and model) are existing.
However, the keys that I retrieve in the output I shared do not correspond 
to (some of) the table fields.
So I am struggling to figure out how to push the values provided by key 
names that do not match the fieldnames into my table.

As an example;
the key Symbol needs to put it's value into field 'yahoo_symbol' in the 
model/table

If that would become really complicated I guess I could change the field 
names in the model/table, but I rather not as the trick in itself would 
help me with some other data as well (it's part of the learning curve I 
guess :-) ).

Thanks!
Oscar




Le lundi 8 juin 2015 22:09:05 UTC+2, Oscar Buijten a écrit :
>
> Hi there,
> The python learning curve seems to be steeper than expected :-(
> As yesterday, help converting my php app into python/django will be 
> appreciated.
>
> I have the following:
>
>   snip  ---
> from django.core.management.base import BaseCommand, CommandError
> import json
> from collections import OrderedDict
> from yahoo_finance import Share 
> from data.models import MyichiTickers, MyichiHistoricalData
>
> exchange  = 'AMS'
> startdate = '2014-04-25'
> enddate   = '2014-04-29'
> minimum_avg_daily_volume = '10'
>
> class Command(BaseCommand):
> def handle(self, *args, **options):
> from yahoo_finance import Share 
> from data.models import MyichiTickers
> tickers_for_exchange = MyichiTickers.objects.filter(exchange=exchange)[:2]
> if tickers_for_exchange:
> for tickerlist in tickers_for_exchange:
> ticker = Share(tickerlist.ticker) 
> if ticker.get_avg_daily_volume() > minimum_avg_daily_volume:
> data = json.dumps(ticker.get_historical(startdate, enddate))
> data = json.loads(data)
> print data
>
>   snip  ---
>
> It may not be perfect, but it works.
> I would need to get 'data' into the 'MyichiHistoricalData' model
>
> The output is like this;
>   snip  ---
> [{u'High': u'6.565', u'Symbol': u'AGN.AS', u'Adj_Close': u'6.31564', 
> u'Volume': u'4376000', u'Low': u'6.428', u'Date': u'2014-04-29', u'Close': 
> u'6.551', u'Open': u'6.435'}, {u'High': u'6.479', u'Symbol': u'AGN.AS', 
> u'Adj_Close': u'6.18742', u'Volume': u'3163200', u'Low': u'6.38', u'Date': 
> u'2014-04-28', u'Close': u'6.418', u'Open': u'6.428'}, {u'High': u'6.535', 
> u'Symbol': u'AGN.AS', u'Adj_Close': u'6.18259', u'Volume': u'4780100', 
> u'Low': u'6.379', u'Date': u'2014-04-25', u'Close': u'6.413', u'Open': 
> u'6.529'}]
> [{u'High': u'13.94', u'Symbol': u'AH.AS', u'Adj_Close': u'13.57496', 
> u'Volume': u'2706600', u'Low': u'13.70', u'Date': u'2014-04-29', u'Close': 
> u'13.92', u'Open': u'13.70'}, {u'High': u'13.735', u'Symbol': u'AH.AS', 
> u'Adj_Close': u'13.34091', u'Volume': u'2784700', u'Low': u'13.56', 
> u'Date': u'2014-04-28', u'Close': u'13.68', u'Open': u'13.565'}, {u'High': 
> u'13.675', u'Symbol': u'AH.AS', u'Adj_Close': u'13.23364', u'Volume': 
> u'3012500', u'Low': u'13.44', u'Date': u'2014-04-25', u'Close': u'13.57', 
> u'Open': u'13.545'}]
>   snip  ---
>
> Where I need help it so extract the keys and values and give them the 
> correct model field names in order to save them.
>
> It should be easy really, bt several hours of readin, searching, trial & 
> error haven't given me the trick yet
>
> Any suggestions?
>
> Thanks!
>
> Oscar
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4dc1dbc6-4645-4b4c-a09c-2f99b3569a9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: push yahoo finance json data into database

2015-06-09 Thread Oscar Buijten
Hi James,
Thanks for such a detailed response. I looked at all your links (and 
already had come across some of them)
I guess that my question wasn't specific enough :-(

The table (and model) are existing.
However, the keys that I retrieve in the output I shared do not correspond 
to (some of) the table fields.
So I am struggling to figure out how to push the values provided by key 
names that do not match the fieldnames into my table.
If that would become really complicated I guess I could change the field 
names in the model/table, but I rather not as the trick in itself would 
help me with some other data as well (it's part of the learning curve I 
guess :-) ).
Thanks!
Oscar


As an example;
the key Symbol needs to put it's value into field 'yahoo_symbol' in the 
model/table

Le lundi 8 juin 2015 22:09:05 UTC+2, Oscar Buijten a écrit :
>
> Hi there,
> The python learning curve seems to be steeper than expected :-(
> As yesterday, help converting my php app into python/django will be 
> appreciated.
>
> I have the following:
>
>   snip  ---
> from django.core.management.base import BaseCommand, CommandError
> import json
> from collections import OrderedDict
> from yahoo_finance import Share 
> from data.models import MyichiTickers, MyichiHistoricalData
>
> exchange  = 'AMS'
> startdate = '2014-04-25'
> enddate   = '2014-04-29'
> minimum_avg_daily_volume = '10'
>
> class Command(BaseCommand):
> def handle(self, *args, **options):
> from yahoo_finance import Share 
> from data.models import MyichiTickers
> tickers_for_exchange = MyichiTickers.objects.filter(exchange=exchange)[:2]
> if tickers_for_exchange:
> for tickerlist in tickers_for_exchange:
> ticker = Share(tickerlist.ticker) 
> if ticker.get_avg_daily_volume() > minimum_avg_daily_volume:
> data = json.dumps(ticker.get_historical(startdate, enddate))
> data = json.loads(data)
> print data
>
>   snip  ---
>
> It may not be perfect, but it works.
> I would need to get 'data' into the 'MyichiHistoricalData' model
>
> The output is like this;
>   snip  ---
> [{u'High': u'6.565', u'Symbol': u'AGN.AS', u'Adj_Close': u'6.31564', 
> u'Volume': u'4376000', u'Low': u'6.428', u'Date': u'2014-04-29', u'Close': 
> u'6.551', u'Open': u'6.435'}, {u'High': u'6.479', u'Symbol': u'AGN.AS', 
> u'Adj_Close': u'6.18742', u'Volume': u'3163200', u'Low': u'6.38', u'Date': 
> u'2014-04-28', u'Close': u'6.418', u'Open': u'6.428'}, {u'High': u'6.535', 
> u'Symbol': u'AGN.AS', u'Adj_Close': u'6.18259', u'Volume': u'4780100', 
> u'Low': u'6.379', u'Date': u'2014-04-25', u'Close': u'6.413', u'Open': 
> u'6.529'}]
> [{u'High': u'13.94', u'Symbol': u'AH.AS', u'Adj_Close': u'13.57496', 
> u'Volume': u'2706600', u'Low': u'13.70', u'Date': u'2014-04-29', u'Close': 
> u'13.92', u'Open': u'13.70'}, {u'High': u'13.735', u'Symbol': u'AH.AS', 
> u'Adj_Close': u'13.34091', u'Volume': u'2784700', u'Low': u'13.56', 
> u'Date': u'2014-04-28', u'Close': u'13.68', u'Open': u'13.565'}, {u'High': 
> u'13.675', u'Symbol': u'AH.AS', u'Adj_Close': u'13.23364', u'Volume': 
> u'3012500', u'Low': u'13.44', u'Date': u'2014-04-25', u'Close': u'13.57', 
> u'Open': u'13.545'}]
>   snip  ---
>
> Where I need help it so extract the keys and values and give them the 
> correct model field names in order to save them.
>
> It should be easy really, bt several hours of readin, searching, trial & 
> error haven't given me the trick yet
>
> Any suggestions?
>
> Thanks!
>
> Oscar
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e07755cc-69e2-4a64-b44c-04041ae6df32%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: push yahoo finance json data into database

2015-06-08 Thread James Schneider
On Mon, Jun 8, 2015 at 1:09 PM, Oscar Buijten <oscar.buij...@gmail.com> wrote:
>
> Hi there,
> The python learning curve seems to be steeper than expected :-(
> As yesterday, help converting my php app into python/django will be 
> appreciated.
>
> I have the following:
>
>   snip  ---

What does your MyichiHistoricalData model look like? That will be the
primary driver on how you extract the values into the right model
attributes.

If your (required) model fields exactly match the ones provided by
your JSON data, creating/updating the models is probably something as
simple as what is shown in this SO post:

http://stackoverflow.com/a/11487626

If this is a command that will update existing records in addition to
creating them (if this command runs at regular intervals), you may
also want to use update_or_create as opposed to the .update()
mentioned in the SO post.

https://docs.djangoproject.com/en/dev/ref/models/querysets/#update-or-create

Or if you are always going to create new objects based on the incoming
data, look into using bulk_create:

https://docs.djangoproject.com/en/dev/ref/models/querysets/#bulk-create

That will save queries and processing time, but be sure to read the caveats.


> I would need to get 'data' into the 'MyichiHistoricalData' model
>
> The output is like this;
>   snip  ---
> [{u'High': u'6.565', u'Symbol': u'AGN.AS', u'Adj_Close': u'6.31564', 
> u'Volume': u'4376000', u'Low': u'6.428', u'Date': u'2014-04-29', u'Close': 
> u'6.551', u'Open': u'6.435'}, {u'High': u'6.479', u'Symbol': u'AGN.AS', 
> u'Adj_Close': u'6.18742', u'Volume': u'3163200', u'Low': u'6.38', u'Date': 
> u'2014-04-28', u'Close': u'6.418', u'Open': u'6.428'}, {u'High': u'6.535', 
> u'Symbol': u'AGN.AS', u'Adj_Close': u'6.18259', u'Volume': u'4780100', 
> u'Low': u'6.379', u'Date': u'2014-04-25', u'Close': u'6.413', u'Open': 
> u'6.529'}]
> [{u'High': u'13.94', u'Symbol': u'AH.AS', u'Adj_Close': u'13.57496', 
> u'Volume': u'2706600', u'Low': u'13.70', u'Date': u'2014-04-29', u'Close': 
> u'13.92', u'Open': u'13.70'}, {u'High': u'13.735', u'Symbol': u'AH.AS', 
> u'Adj_Close': u'13.34091', u'Volume': u'2784700', u'Low': u'13.56', u'Date': 
> u'2014-04-28', u'Close': u'13.68', u'Open': u'13.565'}, {u'High': u'13.675', 
> u'Symbol': u'AH.AS', u'Adj_Close': u'13.23364', u'Volume': u'3012500', 
> u'Low': u'13.44', u'Date': u'2014-04-25', u'Close': u'13.57', u'Open': 
> u'13.545'}]
>   snip  ---
>
> Where I need help it so extract the keys and values and give them the correct 
> model field names in order to save them.
>
> It should be easy really, bt several hours of readin, searching, trial & 
> error haven't given me the trick yet
>
> Any suggestions?


You may also want to have a look at the Django deserialization docs:
https://docs.djangoproject.com/en/dev/topics/serialization/#deserializing-data
I'm not sure if they'll help since you are working with an external
data source.

Assuming that the 'Symbol' will be used as a natural key:
https://docs.djangoproject.com/en/dev/topics/serialization/#deserialization-of-natural-keys


Another note: If you haven't already and before you go any further, be
sure to check with your legal team and with Yahoo!'s terms and
conditions on the use of Yahoo!'s finance data for your own
application. You may not be permitted to use their data in this manner
without some sort of agreement with Yahoo! and/or it's subsidiaries,
even though it is "freely" available through an API.

-James
(Not a lawyer)

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciW5jb1%3DLAptK3ee1GydhZ9G1DN7uKjPGSvESs6x7yXtNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


push yahoo finance json data into database

2015-06-08 Thread Oscar Buijten
Hi there,
The python learning curve seems to be steeper than expected :-(
As yesterday, help converting my php app into python/django will be 
appreciated.

I have the following:

  snip  ---
from django.core.management.base import BaseCommand, CommandError
import json
from collections import OrderedDict
from yahoo_finance import Share 
from data.models import MyichiTickers, MyichiHistoricalData

exchange  = 'AMS'
startdate = '2014-04-25'
enddate   = '2014-04-29'
minimum_avg_daily_volume = '10'

class Command(BaseCommand):
def handle(self, *args, **options):
from yahoo_finance import Share 
from data.models import MyichiTickers
tickers_for_exchange = MyichiTickers.objects.filter(exchange=exchange)[:2]
if tickers_for_exchange:
for tickerlist in tickers_for_exchange:
ticker = Share(tickerlist.ticker) 
if ticker.get_avg_daily_volume() > minimum_avg_daily_volume:
data = json.dumps(ticker.get_historical(startdate, enddate))
data = json.loads(data)
print data

  snip  ---

It may not be perfect, but it works.
I would need to get 'data' into the 'MyichiHistoricalData' model

The output is like this;
  snip  ---
[{u'High': u'6.565', u'Symbol': u'AGN.AS', u'Adj_Close': u'6.31564', 
u'Volume': u'4376000', u'Low': u'6.428', u'Date': u'2014-04-29', u'Close': 
u'6.551', u'Open': u'6.435'}, {u'High': u'6.479', u'Symbol': u'AGN.AS', 
u'Adj_Close': u'6.18742', u'Volume': u'3163200', u'Low': u'6.38', u'Date': 
u'2014-04-28', u'Close': u'6.418', u'Open': u'6.428'}, {u'High': u'6.535', 
u'Symbol': u'AGN.AS', u'Adj_Close': u'6.18259', u'Volume': u'4780100', 
u'Low': u'6.379', u'Date': u'2014-04-25', u'Close': u'6.413', u'Open': 
u'6.529'}]
[{u'High': u'13.94', u'Symbol': u'AH.AS', u'Adj_Close': u'13.57496', 
u'Volume': u'2706600', u'Low': u'13.70', u'Date': u'2014-04-29', u'Close': 
u'13.92', u'Open': u'13.70'}, {u'High': u'13.735', u'Symbol': u'AH.AS', 
u'Adj_Close': u'13.34091', u'Volume': u'2784700', u'Low': u'13.56', 
u'Date': u'2014-04-28', u'Close': u'13.68', u'Open': u'13.565'}, {u'High': 
u'13.675', u'Symbol': u'AH.AS', u'Adj_Close': u'13.23364', u'Volume': 
u'3012500', u'Low': u'13.44', u'Date': u'2014-04-25', u'Close': u'13.57', 
u'Open': u'13.545'}]
  snip  ---

Where I need help it so extract the keys and values and give them the 
correct model field names in order to save them.

It should be easy really, bt several hours of readin, searching, trial & 
error haven't given me the trick yet

Any suggestions?

Thanks!

Oscar

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c6e16498-8b13-4b4c-b8ec-489a44b1d274%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: JSON data

2015-05-07 Thread Tim Chase
On 2015-05-07 22:32, Thorsten Sanders wrote:
> Am 07.05.2015 17:37, schrieb Tim Chase:
>> Can you provide sample JSON data that others can use
>> for testing?  Which version of Python are you using and which
>> Python JSON library are you using?
>
> The version of python can make quite a big difference, years ago
> with python 2.6 I had the problem that decoding several megabyte of
> json data took over 1 minute with the integrated one, simplejson
> fixed that (only took a few hundred ms) and since 2.7 it works fine
> with the integrated one as well.

I remember there being various JSON libraries over time, and that
there were some performance issues in some of them (thus that bit of
my line of questioning) but didn't remember the particulars. Thanks
for filling in the details.

-tkc



-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150507154248.5cd89434%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.


Re: JSON data

2015-05-07 Thread Thorsten Sanders

Am 07.05.2015 17:37, schrieb Tim Chase:

On 2015-05-07 13:56, palansh agarwal wrote:

processing of json is slow. It takes considerable amount of time to
process data after calling the API.

You seem fairly confident in this.  Do you have the timing
statistics?  Can you provide sample JSON data that others can use
for testing?  Which version of Python are you using and which Python
JSON library are you using?

-tkc



The version of python can make quite a big difference, years ago with 
python 2.6 I had the problem that decoding several megabyte of json data 
took over 1 minute with the integrated one, simplejson fixed that (only 
took a few hundred ms) and since 2.7 it works fine with the integrated 
one as well.


--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/554BCBCB.2000703%40gmx.net.
For more options, visit https://groups.google.com/d/optout.


Re: JSON data

2015-05-07 Thread Tim Chase
On 2015-05-07 13:56, palansh agarwal wrote:
> processing of json is slow. It takes considerable amount of time to
> process data after calling the API.

You seem fairly confident in this.  Do you have the timing
statistics?  Can you provide sample JSON data that others can use
for testing?  Which version of Python are you using and which Python
JSON library are you using?

-tkc



-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150507103749.042807d9%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.


Re: JSON data

2015-05-07 Thread Thomas Levine
> which part is slow?  the API, the processing of the JSON, or the
> display?

And here's how you can check that. Insert the following line between
the different steps that Tim itemized,

print(time.perf_counter())

subtract the numbers that get printed, and then determine which step
is slow.

Alternatively, if your code is written very cleanly, you can use timeit.
https://docs.python.org/3/library/timeit.html

Tom

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150507135234.GA27152%40d1stkfactory.
For more options, visit https://groups.google.com/d/optout.


Re: JSON data

2015-05-06 Thread Tim Chase
On 2015-05-07 02:14, palansh agarwal wrote:
> I am making a django app in which I require to read json data from
> an external API and display data, But it's working very slowly. Any
> suggestions to speed up the process will be appreciated.

which part is slow?  the API, the processing of the JSON, or the
display?

-tkc





-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20150506162720.007aa87d%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.


JSON data

2015-05-06 Thread palansh agarwal
Hello,
I am making a django app in which I require to read json data from an
external API and display data, But it's working very slowly. Any
suggestions to speed up the process will be appreciated.
Regards,

-- 
PALANSH AGARWAL
Y13UC185
Computer Science Engineering
2nd Year
The LNM Institute of Information Technology, Jaipur
Find me on-> http://pygeek.strikingly.com/

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPCyp%2B92FT2F%3DVVigB6N8Fk3ObXhr13AkqFgdWWk9N%3DbfT8BoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Populating Django app db with JSON data

2015-03-06 Thread Collin Anderson
Hi Sandeep,

A snapshot (or at least a diff from the previous one) is stored when you 
run makemigrations.

Collin

On Wednesday, March 4, 2015 at 2:15:41 PM UTC-5, Murthy Sandeep wrote:
>
> Hi 
>
> thanks for the info. 
>
> The docs also say that RunPython runs “custom Python code 
> in a historical context”.  What does that mean exactly?  It seems 
> related to the apps and schema_editor arguments passed to 
> the custom method that will be called by RunPython - is this something 
> like a snapshot of the app model that is stored when I do `python 
> manage.py migrate`? 
>
> Sandeep 
>
>
> > On 2 Mar 2015, at 19:37, aRkadeFR <con...@arkade.info > 
> wrote: 
> > 
> > Hello, 
> > 
> > Indeed, the data migration is the best way. Check out 
> > the documentation here: 
> > 
> https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunPython
>  
> > 
> > You write your function that will be called by the RunPython 
> > and will load your JSON. 
> > Migration are ordered, your first migration will create the 
> > tables and the second (your data migration) will load your 
> > JSON. 
> > 
> > To create an empty migration: 
> > ./manage.py makemigrations  --empty 
> > 
> > You can rename to a useful descriptive name the migration 
> > file. 
> > 
> > Have a good one 
> > 
> > 
> > On 03/02/2015 08:16 AM, Sandeep Murthy wrote: 
> >> Hi 
> >> 
> >> I've tried to get the answer to this question (which is a bit 
> open-ended) on stackoverflow without much success, which 
> >> is basically this: what is the recommended approach to populating a 
> pre-existing Django app database table (generated 
> >> from a model and which is currently empty) with JSON data? 
> >> 
> >> There seem to be several alternatives given in the Django documentation 
> (Django 1.7 manual) which include (1) fixtures, 
> >> (2) SQL scripts, (3) data migrations.  Of these I am a bit confused by 
> the advice in the manual which suggests that (1) 
> >> and (2) are only useful for loading initial data.  That's not what I 
> want to do.  The data that the app needs is going to be 
> >> persistent and permanent because the app is intended to be a web query 
> tool for a large dataset that is currently in the 
> >> form of several JSON files, each containing on average thousands of 
> JSON objects, each object representing an entry 
> >> corresponding to a table entry in a relational db.  The data is not 
> going to be re-loaded or change after entry, and there 
> >> is no user facility for changing the data. 
> >> 
> >> The table has been created using the makemigrations and migrate tools, 
> but is empty.  I just need to populate the 
> >> table with the JSON data.  It seems that I need to write a custom data 
> migration script that will insert the data into the 
> >> table via the interpreter, and then I need to run python manage.py 
> migrate.  Is this the case, and if so, are there 
> >> are examples that I could use? 
> >> 
> >> Thanks in advance for any suggestions. 
> >> 
> >> SM 
> >> -- 
> >> 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...@googlegroups.com . 
> >> To post to this group, send email to django...@googlegroups.com 
> . 
> >> Visit this group at http://groups.google.com/group/django-users. 
> >> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/db5919c5-ace4-4556-b90e-aa47baa26552%40googlegroups.com.
>  
>
> >> For more options, visit https://groups.google.com/d/optout. 
> > 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at http://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/54F42164.6040505%40arkade.info.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d78e387b-9232-4a5a-b6d5-1306b5084913%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Populating Django app db with JSON data

2015-03-04 Thread Murthy Sandeep
Hi

thanks for the info.

The docs also say that RunPython runs “custom Python code
in a historical context”.  What does that mean exactly?  It seems
related to the apps and schema_editor arguments passed to
the custom method that will be called by RunPython - is this something
like a snapshot of the app model that is stored when I do `python manage.py 
migrate`?

Sandeep


> On 2 Mar 2015, at 19:37, aRkadeFR <cont...@arkade.info> wrote:
> 
> Hello,
> 
> Indeed, the data migration is the best way. Check out
> the documentation here:
> https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunPython
> 
> You write your function that will be called by the RunPython
> and will load your JSON.
> Migration are ordered, your first migration will create the
> tables and the second (your data migration) will load your
> JSON.
> 
> To create an empty migration:
> ./manage.py makemigrations  --empty
> 
> You can rename to a useful descriptive name the migration
> file.
> 
> Have a good one
> 
> 
> On 03/02/2015 08:16 AM, Sandeep Murthy wrote:
>> Hi
>> 
>> I've tried to get the answer to this question (which is a bit open-ended) on 
>> stackoverflow without much success, which
>> is basically this: what is the recommended approach to populating a 
>> pre-existing Django app database table (generated
>> from a model and which is currently empty) with JSON data?
>> 
>> There seem to be several alternatives given in the Django documentation 
>> (Django 1.7 manual) which include (1) fixtures,
>> (2) SQL scripts, (3) data migrations.  Of these I am a bit confused by the 
>> advice in the manual which suggests that (1)
>> and (2) are only useful for loading initial data.  That's not what I want to 
>> do.  The data that the app needs is going to be
>> persistent and permanent because the app is intended to be a web query tool 
>> for a large dataset that is currently in the
>> form of several JSON files, each containing on average thousands of JSON 
>> objects, each object representing an entry
>> corresponding to a table entry in a relational db.  The data is not going to 
>> be re-loaded or change after entry, and there
>> is no user facility for changing the data.
>> 
>> The table has been created using the makemigrations and migrate tools, but 
>> is empty.  I just need to populate the
>> table with the JSON data.  It seems that I need to write a custom data 
>> migration script that will insert the data into the
>> table via the interpreter, and then I need to run python manage.py migrate.  
>> Is this the case, and if so, are there
>> are examples that I could use?
>> 
>> Thanks in advance for any suggestions.
>> 
>> SM
>> --
>> 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.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/db5919c5-ace4-4556-b90e-aa47baa26552%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 
> 
> --
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/54F42164.6040505%40arkade.info.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/279E5DB5-57C9-4A85-9EDA-3A9159BE8925%40sandeepmurthy.is.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: Populating Django app db with JSON data

2015-03-02 Thread aRkadeFR

“custom Python code in a historical context”
FMPOV, it means that your code will be run exactly at a certain
schema of your DB. If your migration is the 3rd one, it will
always be run after your first two migrations, thus you will
know exactly your schema.

The schema is passed to your function (as apps and schema_editor)
in order to get your Model class.

Sorry if my explanation wasn't clear, hope it will help at least.

On 03/02/2015 10:27 AM, Murthy Sandeep wrote:

Hi

thanks for the info.

The docs also say that RunPython runs “custom Python code
in a historical context”.  What does that mean exactly?  It seems
related to the apps and schema_editor arguments passed to
the custom method that will be called by RunPython - is this something
like a snapshot of the app model that is stored when I do `python manage.py 
migrate`?

Sandeep



On 2 Mar 2015, at 19:37, aRkadeFR <cont...@arkade.info> wrote:

Hello,

Indeed, the data migration is the best way. Check out
the documentation here:
https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunPython

You write your function that will be called by the RunPython
and will load your JSON.
Migration are ordered, your first migration will create the
tables and the second (your data migration) will load your
JSON.

To create an empty migration:
./manage.py makemigrations  --empty

You can rename to a useful descriptive name the migration
file.

Have a good one


On 03/02/2015 08:16 AM, Sandeep Murthy wrote:

Hi

I've tried to get the answer to this question (which is a bit open-ended) on 
stackoverflow without much success, which
is basically this: what is the recommended approach to populating a 
pre-existing Django app database table (generated
from a model and which is currently empty) with JSON data?

There seem to be several alternatives given in the Django documentation (Django 
1.7 manual) which include (1) fixtures,
(2) SQL scripts, (3) data migrations.  Of these I am a bit confused by the 
advice in the manual which suggests that (1)
and (2) are only useful for loading initial data.  That's not what I want to 
do.  The data that the app needs is going to be
persistent and permanent because the app is intended to be a web query tool for 
a large dataset that is currently in the
form of several JSON files, each containing on average thousands of JSON 
objects, each object representing an entry
corresponding to a table entry in a relational db.  The data is not going to be 
re-loaded or change after entry, and there
is no user facility for changing the data.

The table has been created using the makemigrations and migrate tools, but is 
empty.  I just need to populate the
table with the JSON data.  It seems that I need to write a custom data 
migration script that will insert the data into the
table via the interpreter, and then I need to run python manage.py migrate.  Is 
this the case, and if so, are there
are examples that I could use?

Thanks in advance for any suggestions.

SM
--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db5919c5-ace4-4556-b90e-aa47baa26552%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54F42164.6040505%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54F43A59.60803%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Re: Populating Django app db with JSON data

2015-03-02 Thread aRkadeFR

Hello,

Indeed, the data migration is the best way. Check out
the documentation here:
https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunPython

You write your function that will be called by the RunPython
and will load your JSON.
Migration are ordered, your first migration will create the
tables and the second (your data migration) will load your
JSON.

To create an empty migration:
./manage.py makemigrations  --empty

You can rename to a useful descriptive name the migration
file.

Have a good one


On 03/02/2015 08:16 AM, Sandeep Murthy wrote:

Hi

I've tried to get the answer to this question (which is a bit 
open-ended) on stackoverflow without much success, which
is basically this: what is the recommended approach to populating a 
pre-existing Django app database table (generated

from a model and which is currently empty) with JSON data?

There seem to be several alternatives given in the Django 
documentation (Django 1.7 manual) which include (1) fixtures,
(2) SQL scripts, (3) data migrations.  Of these I am a bit confused by 
the advice in the manual which suggests that (1)
and (2) are only useful for loading initial data.  That's not what I 
want to do.  The data that the app needs is going to be
persistent and permanent because the app is intended to be a web query 
tool for a large dataset that is currently in the
form of several JSON files, each containing on average thousands of 
JSON objects, each object representing an entry
corresponding to a table entry in a relational db.  The data is not 
going to be re-loaded or change after entry, and there

is no user facility for changing the data.

The table has been created using the makemigrations and migratetools, 
but is empty.  I just need to populate the
table with the JSON data.  It seems that I need to write a custom data 
migration script that will insert the data into the
table via the interpreter, and then I need to run python manage.py 
migrate.  Is this the case, and if so, are there

are examples that I could use?

Thanks in advance for any suggestions.

SM
--
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 
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com 
<mailto:django-users@googlegroups.com>.

Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db5919c5-ace4-4556-b90e-aa47baa26552%40googlegroups.com 
<https://groups.google.com/d/msgid/django-users/db5919c5-ace4-4556-b90e-aa47baa26552%40googlegroups.com?utm_medium=email_source=footer>.

For more options, visit https://groups.google.com/d/optout.


--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54F42164.6040505%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Populating Django app db with JSON data

2015-03-01 Thread Sandeep Murthy
Hi

I've tried to get the answer to this question (which is a bit open-ended) 
on stackoverflow without much success, which
is basically this: what is the recommended approach to populating a 
pre-existing Django app database table (generated
from a model and which is currently empty) with JSON data?

There seem to be several alternatives given in the Django documentation 
(Django 1.7 manual) which include (1) fixtures,
(2) SQL scripts, (3) data migrations.  Of these I am a bit confused by the 
advice in the manual which suggests that (1)
and (2) are only useful for loading initial data.  That's not what I want 
to do.  The data that the app needs is going to be
persistent and permanent because the app is intended to be a web query tool 
for a large dataset that is currently in the 
form of several JSON files, each containing on average thousands of JSON 
objects, each object representing an entry
corresponding to a table entry in a relational db.  The data is not going 
to be re-loaded or change after entry, and there
is no user facility for changing the data.

The table has been created using the makemigrations and migrate tools, but 
is empty.  I just need to populate the
table with the JSON data.  It seems that I need to write a custom data 
migration script that will insert the data into the
table via the interpreter, and then I need to run python manage.py migrate.  
Is this the case, and if so, are there
are examples that I could use?

Thanks in advance for any suggestions.

SM

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db5919c5-ace4-4556-b90e-aa47baa26552%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django sometimes shows partial (incomplete) json data in production env

2015-02-24 Thread Javier Guerra Giraldez
On Mon, Feb 23, 2015 at 11:54 PM, George Mejia  wrote:
>
> Besides, this only happens on production env ...  The code is fine and works 
> on production env, and the behaviour was normal before ...  this also happens 
> for others queries (all only in production), I wonder what is cutting 
> conexion ? if so, when this occurs ?


check the time needed to generate that response.  this sounds like
some serve-enforced timeout.

(why to send textual data as a picture??)


-- 
Javier

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFkDaoTTU%2B75G1uUMmK5Uhq-i4QOuYTKBgtUeMGSx52uzJu_fA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django sometimes shows partial (incomplete) json data in production env

2015-02-24 Thread George Mejia
I request some json data by some url, sometimes it works fine and *sometimes 
doesn't* ... I looked another related cuestion here 
<https://github.com/django-tastypie/django-tastypie/issues/799>, but it 
seems to recommend not change content-length by middleware ... my json data 
incomplete is as image below shows:

<http://i.stack.imgur.com/ofHzt.png>



Besides, this only happens on production env ...  The code is fine and 
works on production env, and the behaviour was normal before ...  this also 
happens for others queries (all only in production), I wonder what is 
cutting conexion ? if so, when this occurs ?

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a2f5d39a-3b4c-4c37-bc4d-88e3e664be5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-07 Thread Henry Versemann
Scot, Thanks for the response. I will try it first thing Monday morning. If 
I have any other questions I may post them then, but this should get most 
of it for me. Thanks again. Henry

On Saturday, February 7, 2015 at 1:35:39 AM UTC-6, Scot Hacker wrote:
>
> On Friday, February 6, 2015 at 9:39:00 AM UTC-8, Henry Versemann wrote:
>>
>> Scot, Thanks for the reply. OK I've gotten down to the point to where I 
>> have my version of your json_data in your code below, but I'm not sure I 
>> understand exactly what your code is doing, after you have the json_data 
>> variable contents. In my case the first object of response data that I'm 
>> trying to use is a list of two items, with each item containing multiple 
>> keys and internal or sub objects within them.
>>
>
> Once your data comes back from the API and has been converted to python 
> data structures, it's up to you to parse and extract from it what you need 
> - every situation is different. All you need to know is that you access 
> list items by their index, and dictionary items by quoted key name. So if I 
> assign the response object you show here to a variable "data", I can do the 
> following:
>
> print(data[0]['parameters'])
> print(data[0]['parameters']['extra_text'])
> print(data[1]['attachment']['display_name'])
>
> and the result is:
>
> {u'enrollment_term_id': u'', u'extra_text': u'Term: All Terms;'}
> Term: All Terms;
> grade_export_csv_22_Oct_2013_2_27551-0.csv
>
> Hope this helps!
>
> ./s
>  
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5a3b2690-9bfa-4ac9-9a16-76390a5b63ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-07 Thread JSON CSV


On Friday, February 6, 2015 at 5:10:32 AM UTC+10, Henry Versemann wrote:
>
> I have a django view (django v. 1.7 ; python v. 2.7.8) which currently and 
> successfully sends a request to an api, and receives a good response back. 
> I'm sending and receiving using the 'requests' library (v. 2.4.3). Now in 
> addition to sending the raw response data back in an HttpResponse I would 
> also like to strip out some of the data and create a summary report of it, 
> to also send back in my HttpResponse.
>
>
>
In case you want to do ad-hoc reports based on JSON data - you may find it 
useful to upload the JSON data to our website https://json-csv.com.  A 
spreadsheet is produced from the API which you can use in Excel to chart on 
/ summarize etc.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b68fa69f-fe11-4ed7-a447-5b8f5492f1cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-06 Thread Scot Hacker
On Friday, February 6, 2015 at 9:39:00 AM UTC-8, Henry Versemann wrote:
>
> Scot, Thanks for the reply. OK I've gotten down to the point to where I 
> have my version of your json_data in your code below, but I'm not sure I 
> understand exactly what your code is doing, after you have the json_data 
> variable contents. In my case the first object of response data that I'm 
> trying to use is a list of two items, with each item containing multiple 
> keys and internal or sub objects within them.
>

Once your data comes back from the API and has been converted to python 
data structures, it's up to you to parse and extract from it what you need 
- every situation is different. All you need to know is that you access 
list items by their index, and dictionary items by quoted key name. So if I 
assign the response object you show here to a variable "data", I can do the 
following:

print(data[0]['parameters'])
print(data[0]['parameters']['extra_text'])
print(data[1]['attachment']['display_name'])

and the result is:

{u'enrollment_term_id': u'', u'extra_text': u'Term: All Terms;'}
Term: All Terms;
grade_export_csv_22_Oct_2013_2_27551-0.csv

Hope this helps!

./s
 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/428cc652-220e-44d8-8818-33725c0b141f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-06 Thread Henry Versemann
Thanks Larry.

On Thursday, February 5, 2015 at 1:17:37 PM UTC-6, larry@gmail.com 
wrote:
>
> On Thu, Feb 5, 2015 at 2:10 PM, Henry Versemann  > wrote: 
> > I have a django view (django v. 1.7 ; python v. 2.7.8) which currently 
> and 
> > successfully sends a request to an api, and receives a good response 
> back. 
> > I'm sending and receiving using the 'requests' library (v. 2.4.3). Now 
> in 
> > addition to sending the raw response data back in an HttpResponse I 
> would 
> > also like to strip out some of the data and create a summary report of 
> it, 
> > to also send back in my HttpResponse. 
> > 
> > I can see the good response data from the request in my command prompt 
> > window, and it contains a list of items inside of the object to which 
> I've 
> > assigned the response data. So my question is how do I get at the list 
> of 
> > items that has been returned back to me as well as all of the data 
> > (key/value pairs) contained in each list item? 
> > 
> > I'm sure there must be some kind of conversion process that I have to 
> run 
> > the raw response data through. I just haven't out what it is yet. 
> > 
> > I've never tried to do this before, from within a django view. If I were 
> > trying to do this on the client side I would use something like this: 
> > 
> >   mydata = jQuery.parseJSON(data); 
> > 
> > to make the data accessible, but never having done anything like this 
> before 
> > on the server side I haven't found anything yet that's been useful or 
> has 
> > worked. 
> > 
> > I would appreciate any help anyone can offer, while I continue to search 
> for 
> > an answer. 
>
> See: https://docs.python.org/3.3/library/json.html 
>
> e.g.: 
>
> import json 
> jsonIn = json.loads(request.POST['json_content']) 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9ac36742-6c5d-43e7-a33e-93f06b46f9aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-06 Thread Henry Versemann
Scot, Thanks for the reply. OK I've gotten down to the point to where I 
have my version of your json_data in your code below, but I'm not sure I 
understand exactly what your code is doing, after you have the json_data 
variable contents. In my case the first object of response data that I'm 
trying to use is a list of two items, with each item containing multiple 
keys and internal or sub objects within them. 
Can you please explain your code after you have the json_data variable 
formatted further? I'm guessing you're doing some kind of further required 
conversion of the data, and if so I'm not sure I understand why those 
conversions are necessary and being done.
My current piece of response data that I'm trying to work with looks like 
this(when I print it in my command prompt window):


[
{
u'status': u'complete', 
u'parameters': 
{
u'enrollment_term_id': u'', 
u'extra_text': u'Term: All Terms;'
}, 
u'file_url': 
u'https://stchas.test.instructure.com/accounts/1/files/7787/download', 
u'attachment': 
{
u'display_name': 
u'grade_export_csv_10_Feb_2014_40_18363-0.csv', 
u'unlock_at': None, 
u'url': 
u'https://stchas.test.instructure.com/files/7787/download?download_frd=1=nEU8FRMgfMaCFUK0NoIXiGMaQj0M
xWWJ4BM7PrMU', 
u'created_at': u'2014-02-10T15:26:24Z', 
u'updated_at': u'2014-02-10T15:26:24Z', 
u'filename': 
u'1392045984_664__grade_export_csv_10_Feb_2014_40_18363-0.csv', 
u'lock_at': None, 
u'thumbnail_url': None, 
u'hidden_for_user': False, 
u'locked': False, 
u'hidden': False, 
u'locked_for_user': False, 
u'content-type': u'text/csv', 
u'id': 7787, 
u'size': 4744
}, 
u'report': u'grade_export_csv', 
u'progress': 100, 
u'id': 40
}, 
{
u'status': u'complete', 
u'parameters': 
{
u'enrollment_term_id': u'', 
u'extra_text': u'Term: All Terms;'
}, 
u'file_url': 
u'https://stchas.test.instructure.com/accounts/1/files/1033/download', 
u'attachment': 
{
u'display_name': u'grade_export_csv_22_Oct_2013_2_27551-0.csv', 
u'unlock_at': None, 
u'url': 
u'https://stchas.test.instructure.com/files/1033/download?download_frd=1=uhw0oyfb0f3m4GtgJAVvwQkRlDfK0kCbg200SIu4',
 

u'created_at': u'2013-10-22T19:15:45Z', 
u'updated_at': u'2013-10-22T19:15:45Z', 
u'filename': u'grade_export_csv_22_Oct_2013_2_27551-0.csv', 
u'lock_at': None, 
u'thumbnail_url': None, 
u'hidden_for_user':False, 
u'locked': False, 
u'hidden': False, 
u'locked_for_user': False, 
u'content-type': u'text/csv', 
u'id': 1033, 
u'size': 395
}, 
u'report': u'grade_export_csv',
u'progress': 100, 
u'id': 2
}
]

So far I've tried to access the objects inside the list like I normally 
would in python using indexing for the list items like this:

lstobjct = rspnslist[index]

but so far all I've gotten from this is an "exceptions.AttributeError". 

Thanks again for the help.  

On Friday, February 6, 2015 at 9:54:03 AM UTC-6, Scot Hacker wrote:

> On Thursday, February 5, 2015 at 11:10:32 AM UTC-8, Henry Versemann wrote:
>>
>> I have a django view (django v. 1.7 ; python v. 2.7.8) which currently 
>> and successfully sends a request to an api, and receives a good response 
>> back. I'm sending and receiving using the 'requests' library (v. 2.4.3). 
>> Now in addition to sending the raw response data back in an HttpResponse I 
>> would also like to strip out some of the data and create a summary report 
>> of it, to also send back in my HttpResponse.
>>
> What Larry said - you need to convert the javascript data format into a 
> python data format. json.loads() will do that for you. Here's a working 
> example: 
>
>
> import json
>
> def get_nyt_news():
> # NYT API data
> response = requests.get(
> '
> http://api.nytimes.com/svc/mostpopular/v2/mostshared/all-sections/7.json?api-key={apikey}'.format(apikey=settings.NYT_API_KEY)
> )
>
> json_data = json.loads(response.text)
> data = json_data['results'][0:4]
>
> # Rewrite data to conform internal links
> for d in data:
> d['get_absolute_url'] = d['url']
>
> return {'object_list': data}
>
>

-- 
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.
To view this discussion on 

Re: how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-06 Thread Scot Hacker
On Thursday, February 5, 2015 at 11:10:32 AM UTC-8, Henry Versemann wrote:
>
> I have a django view (django v. 1.7 ; python v. 2.7.8) which currently and 
> successfully sends a request to an api, and receives a good response back. 
> I'm sending and receiving using the 'requests' library (v. 2.4.3). Now in 
> addition to sending the raw response data back in an HttpResponse I would 
> also like to strip out some of the data and create a summary report of it, 
> to also send back in my HttpResponse.
>
What Larry said - you need to convert the javascript data format into a 
python data format. json.loads() will do that for you. Here's a working 
example: 


import json

def get_nyt_news():
# NYT API data
response = requests.get(

'http://api.nytimes.com/svc/mostpopular/v2/mostshared/all-sections/7.json?api-key={apikey}'.format(apikey=settings.NYT_API_KEY)
)

json_data = json.loads(response.text)
data = json_data['results'][0:4]

# Rewrite data to conform internal links
for d in data:
d['get_absolute_url'] = d['url']

return {'object_list': data}

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b7300a03-2200-485f-9d4e-227f08cef92d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-05 Thread Larry Martell
On Thu, Feb 5, 2015 at 2:10 PM, Henry Versemann  wrote:
> I have a django view (django v. 1.7 ; python v. 2.7.8) which currently and
> successfully sends a request to an api, and receives a good response back.
> I'm sending and receiving using the 'requests' library (v. 2.4.3). Now in
> addition to sending the raw response data back in an HttpResponse I would
> also like to strip out some of the data and create a summary report of it,
> to also send back in my HttpResponse.
>
> I can see the good response data from the request in my command prompt
> window, and it contains a list of items inside of the object to which I've
> assigned the response data. So my question is how do I get at the list of
> items that has been returned back to me as well as all of the data
> (key/value pairs) contained in each list item?
>
> I'm sure there must be some kind of conversion process that I have to run
> the raw response data through. I just haven't out what it is yet.
>
> I've never tried to do this before, from within a django view. If I were
> trying to do this on the client side I would use something like this:
>
>   mydata = jQuery.parseJSON(data);
>
> to make the data accessible, but never having done anything like this before
> on the server side I haven't found anything yet that's been useful or has
> worked.
>
> I would appreciate any help anyone can offer, while I continue to search for
> an answer.

See: https://docs.python.org/3.3/library/json.html

e.g.:

import json
jsonIn = json.loads(request.POST['json_content'])

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY4cV8ion7%3DY6e_nmCvzdTF7VCejA%2BCDRvx_JUZoJ%3D_HMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


how to access json data value(s) returned back to django view from 'GET' request to an api

2015-02-05 Thread Henry Versemann


I have a django view (django v. 1.7 ; python v. 2.7.8) which currently and 
successfully sends a request to an api, and receives a good response back. 
I'm sending and receiving using the 'requests' library (v. 2.4.3). Now in 
addition to sending the raw response data back in an HttpResponse I would 
also like to strip out some of the data and create a summary report of it, 
to also send back in my HttpResponse.

I can see the good response data from the request in my command prompt 
window, and it contains a list of items inside of the object to which I've 
assigned the response data. So my question is how do I get at the list of 
items that has been returned back to me as well as all of the data 
(key/value pairs) contained in each list item?

I'm sure there must be some kind of conversion process that I have to run 
the raw response data through. I just haven't out what it is yet.

I've never tried to do this before, from within a django view. If I were 
trying to do this on the client side I would use something like this:

  mydata = jQuery.parseJSON(data);

to make the data accessible, but never having done anything like this 
before  on the server side I haven't found anything yet that's been useful 
or has worked.

I would appreciate any help anyone can offer, while I continue to search 
for an answer.

Thanks.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8f661a72-2b2f-4836-a8ee-aac687f10e13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to receive json data using HTTP POST request in Django 1.6?

2014-06-10 Thread Alok Singh Mahor
thank you Malcolm, I will try that too


On Tue, Jun 10, 2014 at 4:47 PM, Malcolm Box <malc...@tellybug.com> wrote:

> Simplest answer is to use Django Rest Framework, which makes this
> extremely easy.
>
> Malcolm
>
>
> On Monday, 9 June 2014 11:20:05 UTC+1, Alok Singh Mahor wrote:
>>
>> Hi all,
>>
>> I am trying to receive JSON data using HTTP POST in django 1.6.
>> I tried using request.POST['data'], request.raw_post_data, request.body
>> but none is working for me.
>> I have posted question and code at http://stackoverflow.com/
>> questions/24068576/how-to-receive-json-data-using-http-
>> post-request-in-django-1-6
>>
>> please tell me how to achieve this in django 1.6
>>
>  --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/78563526-cf0a-4cfc-b8f4-e1551eb4fa51%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/78563526-cf0a-4cfc-b8f4-e1551eb4fa51%40googlegroups.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG2qO83h0C-TxPMDv2b9455b6Us5KnrggE_aqgCPKLq2cZ6y5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to receive json data using HTTP POST request in Django 1.6?

2014-06-10 Thread Malcolm Box
Simplest answer is to use Django Rest Framework, which makes this extremely 
easy.

Malcolm

On Monday, 9 June 2014 11:20:05 UTC+1, Alok Singh Mahor wrote:
>
> Hi all,
>
> I am trying to receive JSON data using HTTP POST in django 1.6.
> I tried using request.POST['data'], request.raw_post_data, request.body 
> but none is working for me. 
> I have posted question and code at 
> http://stackoverflow.com/questions/24068576/how-to-receive-json-data-using-http-post-request-in-django-1-6
>
> please tell me how to achieve this in django 1.6
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/78563526-cf0a-4cfc-b8f4-e1551eb4fa51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to receive json data using HTTP POST request in Django 1.6?

2014-06-09 Thread Alok Singh Mahor
Hi all,

I am trying to receive JSON data using HTTP POST in django 1.6.
I tried using request.POST['data'], request.raw_post_data, request.body but 
none is working for me. 
I have posted question and code at 
http://stackoverflow.com/questions/24068576/how-to-receive-json-data-using-http-post-request-in-django-1-6

please tell me how to achieve this in django 1.6

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f09a72b2-c6a5-4af9-8d41-da585f82d7c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to call url and get json data

2013-10-21 Thread Sanjay Bhangar
Mahantesh,

On Mon, Oct 21, 2013 at 3:48 PM, Mahantesh U <mahant.ullaga...@gmail.com> wrote:
> Hi,
>
>How to call the below url in django in views file:
>
>
>
> http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=O-lzp4Hyqp8=json
>
>   The above api returns json data which further i need to use and fill those
> in html file.
>
>
> HttpResponse('http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=O-lzp4Hyqp8=json')
>
>  Is this correct way to call to get json data?
>

No.

Think about what you need to do - you need to fetch this JSON in your
view, process it, and then send those variables as "context" to your
template to be able to render them.

So, first, you need to fetch the JSON data in your python view. This
can be accomplished with something like:

import urllib2
json_string = 
urllib2.urlopen('http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=O-lzp4Hyqp8=json').read()

^ this will store the results of that webpage into a variable called
"json_string". You can also look at the "requests" library to fetch
data from URLs in python, but urllib2 should be fine as well.

Then, we need to convert the json_string into a python dict:

import json
data = json.loads(json_string)

Now you will have a python dict with all the data in a variable called "data"

Now you can process this data, add other context data that you need,
etc. and finally render the template with something like:

from django.shortcuts import render
return render(request, "template_name.html", data)

Then in your template you can output like {{ author_name }}, {{
author_url }}, etc. as needed.

Hope that makes sense.
All the best,
Sanjay


> Thanks in advance
>
>
>
>
>
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/10216c68-f54f-4ea9-9e9c-6d0d03227bc0%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG3W7ZFrBP8cuLxupFArEt1bXT7urb%3DNqtrFVpcxGsWev46-AA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


How to call url and get json data

2013-10-21 Thread Mahantesh U
Hi,

   How to call the below url in django in views file:


  
 
http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=O-lzp4Hyqp8=json

  The above api returns json data which further i need to use and fill 
those in html file.
  
  
HttpResponse('http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=O-lzp4Hyqp8=json')

 Is this correct way to call to get json data?

Thanks in advance






-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/10216c68-f54f-4ea9-9e9c-6d0d03227bc0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Extracting json data for parsing from HTTP GET

2013-04-02 Thread Eduardo Gonzalo Espinoza Carreon
I had the same problem. This worked for me, just wrting this because I 
couldn't find an answer in stackoverflow or other sites. 

+1

Thanks

On Thursday, September 2, 2010 8:19:37 AM UTC-3, irum wrote:
>
> Thank you so much, it worked:)...Now I just have to play with parsing 
> json that I think I can manage. 
>
> Thanks again:) 
>
> Irum 
>
> On Sep 2, 1:11 pm, Daniel Roseman  wrote: 
> > On Sep 2, 10:37 am, irum  wrote: 
> > 
> > 
> > 
> > > Hi, 
> > > Thanks for your prompt reply. 
> > > I have tried both the things but I get the same error. 
> > > With, 
> > > x = json.loads(p.read()) 
> > >print x 
> > 
> > > I get following error:  'HttpResponse' object has no attribute 
> > > 'read' 
> > > Also I get same error with, json.dumps(p.read()), and same when I use 
> > > loads and dumps as load and dump without s. 
> > 
> > > Then, I tried the other option, 
> > 
> > > x = json.dump(p) 
> > > print x 
> > 
> > > I get the following error: dump() takes at least 2 arguments (1 given) 
> > > What would be the second argument, I googled on this but find no 
> > > helpful tips as everything written is too complicated. 
> > 
> > > And with: 
> > >x = json.load(p) 
> > >print x 
> > 
> > > 'HttpResponse' object has no attribute 'read' 
> > 
> > > In all the examples, p is the HttpResponse object I get. 
> > 
> > > Looking forward, 
> > > Irum 
> > 
> > Apologies for steering you wrong - that'll teach me to post without 
> > checking. 
> > 
> > You're right that HttpResponse doesn't have a read() method, contrary 
> > to what I thought. So neither of those methods will work. Instead, get 
> > the content of the response and call loads() on that: 
> > 
> > json.loads(p.content) 
> > 
> > -- 
> > DR.

-- 
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.




Re: How do i view json data returned from django

2012-03-01 Thread Bill Freeman
On Thu, Mar 1, 2012 at 8:29 AM, Shawn Milochik <sh...@milochik.com> wrote:
> On 03/01/2012 07:48 AM, Stanwin Siow wrote:
>>
>> Hello,
>>
>> I want to view the actual json data from django view, is there anyway i
>> can do that before i parse it into jQuery?
>>
>
>
> Assuming that you have a dictionary named "return_data," this will do it:
>
> return HttpResponse(simplejson.dumps(return_data), mimetype =
> "application/json")
>

Or, if you want to see it coming from the django site, use curl (always there
on linux, available if not there on OS/x, there are versions for Windows, I'm
sure but there is also cygwin.

Or you can use urllib2 to fetch it from a python prompt.

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

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



Re: How do i view json data returned from django

2012-03-01 Thread Shawn Milochik

On 03/01/2012 07:48 AM, Stanwin Siow wrote:

Hello,

I want to view the actual json data from django view, is there anyway i can do 
that before i parse it into jQuery?




Assuming that you have a dictionary named "return_data," this will do it:

return HttpResponse(simplejson.dumps(return_data), mimetype = 
"application/json")


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



How do i view json data returned from django

2012-03-01 Thread Stanwin Siow
Hello,

I want to view the actual json data from django view, is there anyway i can do 
that before i parse it into jQuery?

Below are my two methods



def refresh_list(request):
if request.method == 'POST':
if 'name_input2' in request.POST:
username = request.POST['name_input2']
print username
refresh_keyword = get_keyword_subscription_dict(username)
#message = refresh_keyword
response = simplejson.dumps({'new_list': refresh_keyword})
return HttpResponse(response, mimetype='application/json')
print 'Success'   
else:
response = simplejson.dumps({'success':'False'})
if request.is_ajax():
return HttpResponse(response, mimetype='application/json')
else:
return HttpResponseRedirect("/")



def get_keyword_subscription_dict(userid = None, keyword = None):
try:
keyword_subscription_dict = {}
if(userid):
cf = settings.cf_users_kw
list_of_keywords_for_user_cf = cf.get(userid, columns=['keyword'])
keyword_subscription_dict = 
ujson.decode(list_of_keywords_for_user_cf['keyword'])
if(keyword):
 return simplejson.dumps(keyword_subscription_dict[keyword])
return simplejson.dumps(keyword_subscription_dict)
except:
return simplejson.dumps('\\')

Do appreciate any help i can get

Thanks!

Best Regards,

Stanwin Siow



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



Re: Bizarre QueryDict behavior grouping json data into a single key

2011-06-11 Thread Andres


On Jun 11, 3:59 pm, bruno desthuilliers
 wrote:
> On 11 juin, 14:36, Andres  wrote:
>
>
>
>
>
>
>
>
>
> > I'm experiencing a really bizarre behavior when using the test client
> > in django.
>
> > I'm using a POST to send data to my django app. I usually do this from
> > an iPhone app and/or a test html form. On the server side, this is how
> > I handle it:
>
> > def handle_query(request):
> >    print request
> >    q                   =   con.QueryLog()
> >    q.ID              =   request.POST.get('ID', '')
> >    q.device            =   request.POST.get('device-model', '')
> >    
>
> > That print statement looks like what you would expect, i.e. each
> > parameter in the post request is turned into a key in the dictionary:
>
> > POST: > [u'v3d0'],
>
> > However, I started writing some tests using django's test client, and
> > no matter what I try, the dictionary of POST parameters I send in the
> > post request get bunched into a single key in the QueryDict. Allow me
> > to illustrate with some code:
>
> > class SearchTest(TestCase):
> >     def setUp(self):
> >         pass
>
> >     def test_search(self):
> >         request = HttpRequest()
>
> >         data = '{"amzn_locale":"com"}'
>
> That's a string representation of plain dict.
>
> >         # request._raw_post_data = data
> >         resp = self.client.post('/is/',
> >                                  data=data,
> >                                  content_type='application/x-www-form-
> > urlencoded',
> >                                  # content_type='application/json',
> >                                 )
> > The same print statement on the server side shows the inexplicable
> > grouping of the dictionary into a string:
>
> > POST:,
>
> What else did you expect exactly ? You're supposed to pass a dict, not
> a string representation of a dict.
>
> > If I set data to an actual dictionary, same thing
>
> > data = '{"amzn_locale":"com"}'
>
> This is the exact same string. Remove the surrounding single quotes if
> you want a dict litteral.
Sorry that was a typo in the post. The same behavior happens with the
following:

  data = {"amzn_locale":"com"}

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



Re: Bizarre QueryDict behavior grouping json data into a single key

2011-06-11 Thread bruno desthuilliers
On 11 juin, 14:36, Andres  wrote:
> I'm experiencing a really bizarre behavior when using the test client
> in django.
>
> I'm using a POST to send data to my django app. I usually do this from
> an iPhone app and/or a test html form. On the server side, this is how
> I handle it:
>
> def handle_query(request):
>    print request
>    q                   =   con.QueryLog()
>    q.ID              =   request.POST.get('ID', '')
>    q.device            =   request.POST.get('device-model', '')
>    
>
> That print statement looks like what you would expect, i.e. each
> parameter in the post request is turned into a key in the dictionary:
>
> POST: [u'v3d0'],
>
> However, I started writing some tests using django's test client, and
> no matter what I try, the dictionary of POST parameters I send in the
> post request get bunched into a single key in the QueryDict. Allow me
> to illustrate with some code:
>
> class SearchTest(TestCase):
>     def setUp(self):
>         pass
>
>     def test_search(self):
>         request = HttpRequest()
>
>         data = '{"amzn_locale":"com"}'

That's a string representation of plain dict.

>         # request._raw_post_data = data
>         resp = self.client.post('/is/',
>                                  data=data,
>                                  content_type='application/x-www-form-
> urlencoded',
>                                  # content_type='application/json',
>                                 )
> The same print statement on the server side shows the inexplicable
> grouping of the dictionary into a string:
>
> POST:,

What else did you expect exactly ? You're supposed to pass a dict, not
a string representation of a dict.

> If I set data to an actual dictionary, same thing
>
> data = '{"amzn_locale":"com"}'

This is the exact same string. Remove the surrounding single quotes if
you want a dict litteral.

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



Bizarre QueryDict behavior grouping json data into a single key

2011-06-11 Thread Andres
I'm experiencing a really bizarre behavior when using the test client
in django.

I'm using a POST to send data to my django app. I usually do this from
an iPhone app and/or a test html form. On the server side, this is how
I handle it:

def handle_query(request):
   print request
   q   =   con.QueryLog()
   q.ID  =   request.POST.get('ID', '')
   q.device=   request.POST.get('device-model', '')
   

That print statement looks like what you would expect, i.e. each
parameter in the post request is turned into a key in the dictionary:

POST:,


If I set data to an actual dictionary, same thing

data = '{"amzn_locale":"com"}'

Setting the request._raw_post_data doesn't change anything. Nor does
changing

content_type='application/json'

Any help would be much appreciated. From this stackoverflow question
it seems like I'm not the first one to run into this
http://stackoverflow.com/questions/2579235/iphone-json-post-request-to-django-server-creates-querydict-within-querydict

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



Re: how do i get access to json data?

2010-11-23 Thread alecx
Thanks for your answer Li.
This solution works for python, I figured this out too.

But how does this work inside a template with javascript?
I use $.getJSON() inside the template to get the data.
Inside the javascript I can access the data with:
   this.fields.name
but
   this.fields.author
does not work.

Any idea?




On 23 Nov., 15:05, Li You  wrote:
> sorry but a mistake.
>
>
>
> On Tue, Nov 23, 2010 at 10:01 PM, Li You  wrote:
> > Maybe this is what you want:
>
> > from json import JSONDecoder
> > s = '''{
> >    "pk": 1,
> >    "model": "store.book",
> >    "fields": {
> >        "name": "Mostly Harmless",
> >        "author": ["Douglas", "Adams"]
> >    }
> > }
> > '''
> > d = JSONDecoder().decode(s)
>
> > print a['fields']['author']
>
> ~~~ should be
> print d['fields']['author']
>
>
>
>
>
> > On Tue, Nov 23, 2010 at 9:45 PM, alecx
> >  wrote:
> >> Hello django users,
>
> >> after several try outs, i am not able to figure out how to access data
> >> in a serialized object.
> >> E. g. how do I get the name "Douglas", "Adams" in the example:
> >>http://docs.djangoproject.com/en/dev/topics/serialization/#deserializ...
>
> >> In javascript i can get e. g. the "name": "Mostly Harmless" with:
> >> this.fields.name.
> >> But how do i get the "author": ["Douglas", "Adams"]?
> >> I tried serveral options, but had no luck.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups 
> >> "Django users" group.
> >> To post to this group, send email to django-us...@googlegroups.com.
> >> To unsubscribe from this group, send email to 
> >> django-users+unsubscr...@googlegroups.com.
> >> For more options, visit this group 
> >> athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > Best Regards!
>
> > Li You
> > University of Science and Technology of China
>
> --
> Best Regards!
>
> Li You
> University of Science and Technology of China

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



Re: how do i get access to json data?

2010-11-23 Thread Li You
sorry but a mistake.

On Tue, Nov 23, 2010 at 10:01 PM, Li You  wrote:
> Maybe this is what you want:
>
> from json import JSONDecoder
> s = '''{
>    "pk": 1,
>    "model": "store.book",
>    "fields": {
>        "name": "Mostly Harmless",
>        "author": ["Douglas", "Adams"]
>    }
> }
> '''
> d = JSONDecoder().decode(s)
>
> print a['fields']['author']
~~~ should be
print d['fields']['author']
>
> On Tue, Nov 23, 2010 at 9:45 PM, alecx
>  wrote:
>> Hello django users,
>>
>> after several try outs, i am not able to figure out how to access data
>> in a serialized object.
>> E. g. how do I get the name "Douglas", "Adams" in the example:
>> http://docs.djangoproject.com/en/dev/topics/serialization/#deserialization-of-natural-keys
>>
>> In javascript i can get e. g. the "name": "Mostly Harmless" with:
>> this.fields.name.
>> But how do i get the "author": ["Douglas", "Adams"]?
>> I tried serveral options, but had no luck.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
>
>
> --
> Best Regards!
>
> Li You
> University of Science and Technology of China
>



-- 
Best Regards!

Li You
University of Science and Technology of China

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



Re: how do i get access to json data?

2010-11-23 Thread Li You
Maybe this is what you want:

from json import JSONDecoder
s = '''{
"pk": 1,
"model": "store.book",
"fields": {
"name": "Mostly Harmless",
"author": ["Douglas", "Adams"]
}
}
'''
d = JSONDecoder().decode(s)

print a['fields']['author']

On Tue, Nov 23, 2010 at 9:45 PM, alecx
 wrote:
> Hello django users,
>
> after several try outs, i am not able to figure out how to access data
> in a serialized object.
> E. g. how do I get the name "Douglas", "Adams" in the example:
> http://docs.djangoproject.com/en/dev/topics/serialization/#deserialization-of-natural-keys
>
> In javascript i can get e. g. the "name": "Mostly Harmless" with:
> this.fields.name.
> But how do i get the "author": ["Douglas", "Adams"]?
> I tried serveral options, but had no luck.
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>



-- 
Best Regards!

Li You
University of Science and Technology of China

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



how do i get access to json data?

2010-11-23 Thread alecx
Hello django users,

after several try outs, i am not able to figure out how to access data
in a serialized object.
E. g. how do I get the name "Douglas", "Adams" in the example:
http://docs.djangoproject.com/en/dev/topics/serialization/#deserialization-of-natural-keys

In javascript i can get e. g. the "name": "Mostly Harmless" with:
this.fields.name.
But how do i get the "author": ["Douglas", "Adams"]?
I tried serveral options, but had no luck.


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



Re: Extracting json data for parsing from HTTP GET

2010-09-02 Thread irum
Thank you so much, it worked:)...Now I just have to play with parsing
json that I think I can manage.

Thanks again:)

Irum

On Sep 2, 1:11 pm, Daniel Roseman  wrote:
> On Sep 2, 10:37 am, irum  wrote:
>
>
>
> > Hi,
> > Thanks for your prompt reply.
> > I have tried both the things but I get the same error.
> > With,
> > x = json.loads(p.read())
> >            print x
>
> > I get following error:  'HttpResponse' object has no attribute
> > 'read'
> > Also I get same error with, json.dumps(p.read()), and same when I use
> > loads and dumps as load and dump without s.
>
> > Then, I tried the other option,
>
> > x = json.dump(p)
> >         print x
>
> > I get the following error: dump() takes at least 2 arguments (1 given)
> > What would be the second argument, I googled on this but find no
> > helpful tips as everything written is too complicated.
>
> > And with:
> >            x = json.load(p)
> >            print x
>
> > 'HttpResponse' object has no attribute 'read'
>
> > In all the examples, p is the HttpResponse object I get.
>
> > Looking forward,
> > Irum
>
> Apologies for steering you wrong - that'll teach me to post without
> checking.
>
> You're right that HttpResponse doesn't have a read() method, contrary
> to what I thought. So neither of those methods will work. Instead, get
> the content of the response and call loads() on that:
>
>     json.loads(p.content)
>
> --
> DR.

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



Re: Extracting json data for parsing from HTTP GET

2010-09-02 Thread Daniel Roseman
On Sep 2, 10:37 am, irum  wrote:
> Hi,
> Thanks for your prompt reply.
> I have tried both the things but I get the same error.
> With,
> x = json.loads(p.read())
>            print x
>
> I get following error:  'HttpResponse' object has no attribute
> 'read'
> Also I get same error with, json.dumps(p.read()), and same when I use
> loads and dumps as load and dump without s.
>
> Then, I tried the other option,
>
> x = json.dump(p)
>         print x
>
> I get the following error: dump() takes at least 2 arguments (1 given)
> What would be the second argument, I googled on this but find no
> helpful tips as everything written is too complicated.
>
> And with:
>            x = json.load(p)
>            print x
>
> 'HttpResponse' object has no attribute 'read'
>
> In all the examples, p is the HttpResponse object I get.
>
> Looking forward,
> Irum

Apologies for steering you wrong - that'll teach me to post without
checking.

You're right that HttpResponse doesn't have a read() method, contrary
to what I thought. So neither of those methods will work. Instead, get
the content of the response and call loads() on that:

json.loads(p.content)

--
DR.

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



Re: Extracting json data for parsing from HTTP GET

2010-09-02 Thread irum
Hi,
Thanks for your prompt reply.
I have tried both the things but I get the same error.
With,
x = json.loads(p.read())
   print x

I get following error:  'HttpResponse' object has no attribute
'read'
Also I get same error with, json.dumps(p.read()), and same when I use
loads and dumps as load and dump without s.

Then, I tried the other option,

x = json.dump(p)
print x

I get the following error: dump() takes at least 2 arguments (1 given)
What would be the second argument, I googled on this but find no
helpful tips as everything written is too complicated.

And with:
   x = json.load(p)
   print x

'HttpResponse' object has no attribute 'read'

In all the examples, p is the HttpResponse object I get.

Looking forward,
Irum




On Sep 2, 12:09 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Sep 2, 9:57 am, irum <irumrauf...@gmail.com> wrote:
>
>
>
> > Hi,
> > I am having problems with extracting json data  for parsing from HTTP
> > GET request.
>
> > What I am doing is that I am receiving json data over HTTP via GET.
> > After debugging much, I have realized that the data also has HTTP
> > headers and other information that serializer is not able to
> > deserialize. How can I extract json data from the complete data
> > (including HTTP information)?
>
> > This is the data I receive, i.e. p, and I want to extract json from it
> > and deserialize it for parsing.
>
> > HTTP/1.0 200 OK Date: Thu, 02 Sep 2010 08:37:39 GMT Server: WSGIServer/
> > 0.1 Python/2.6.4 Content-Type: application/json [{"pk": 33, "model":
> > "hbexample.payment", "fields": {"confirm": true, "pDate": "2010-08-31
> > 10:42:19", "waiting": false, "amount": 33.0, "p_try": 0, "booking":
> > 34}}]
>
> > I have tried json.loads and json.dumps on this data.
>
> > With json.loads(p), I get the following error: expected string or
> > buffer
>
> > With json.dumps(p), I get the following error:
> >  is not JSON
> > serializable
>
> > How do I address this problem? Any help regarding this would be
> > helpful.
>
> > Thanks and Looking forward,
> > Irum
>
> json.loads() and dujmps() work on a string or string-like object.
> HttpResponse is a file-like object, not a string, so you could either
> do loads(p.read()), or - much better - use the load() and dump()
> methods, without the s, directly on the HttpResponse.
> --
> DR.

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



Re: Extracting json data for parsing from HTTP GET

2010-09-02 Thread Daniel Roseman
On Sep 2, 9:57 am, irum <irumrauf...@gmail.com> wrote:
> Hi,
> I am having problems with extracting json data  for parsing from HTTP
> GET request.
>
> What I am doing is that I am receiving json data over HTTP via GET.
> After debugging much, I have realized that the data also has HTTP
> headers and other information that serializer is not able to
> deserialize. How can I extract json data from the complete data
> (including HTTP information)?
>
> This is the data I receive, i.e. p, and I want to extract json from it
> and deserialize it for parsing.
>
> HTTP/1.0 200 OK Date: Thu, 02 Sep 2010 08:37:39 GMT Server: WSGIServer/
> 0.1 Python/2.6.4 Content-Type: application/json [{"pk": 33, "model":
> "hbexample.payment", "fields": {"confirm": true, "pDate": "2010-08-31
> 10:42:19", "waiting": false, "amount": 33.0, "p_try": 0, "booking":
> 34}}]
>
> I have tried json.loads and json.dumps on this data.
>
> With json.loads(p), I get the following error: expected string or
> buffer
>
> With json.dumps(p), I get the following error:
>  is not JSON
> serializable
>
> How do I address this problem? Any help regarding this would be
> helpful.
>
> Thanks and Looking forward,
> Irum

json.loads() and dujmps() work on a string or string-like object.
HttpResponse is a file-like object, not a string, so you could either
do loads(p.read()), or - much better - use the load() and dump()
methods, without the s, directly on the HttpResponse.
--
DR.

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



Extracting json data for parsing from HTTP GET

2010-09-02 Thread irum
Hi,
I am having problems with extracting json data  for parsing from HTTP
GET request.

What I am doing is that I am receiving json data over HTTP via GET.
After debugging much, I have realized that the data also has HTTP
headers and other information that serializer is not able to
deserialize. How can I extract json data from the complete data
(including HTTP information)?

This is the data I receive, i.e. p, and I want to extract json from it
and deserialize it for parsing.

HTTP/1.0 200 OK Date: Thu, 02 Sep 2010 08:37:39 GMT Server: WSGIServer/
0.1 Python/2.6.4 Content-Type: application/json [{"pk": 33, "model":
"hbexample.payment", "fields": {"confirm": true, "pDate": "2010-08-31
10:42:19", "waiting": false, "amount": 33.0, "p_try": 0, "booking":
34}}]


I have tried json.loads and json.dumps on this data.

With json.loads(p), I get the following error: expected string or
buffer

With json.dumps(p), I get the following error:
 is not JSON
serializable

How do I address this problem? Any help regarding this would be
helpful.


Thanks and Looking forward,
Irum

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



Re: Passing JSON data

2010-06-02 Thread Simone Dalla
2010/6/2 ravi krishna <ravi.9...@gmail.com>

> Hi,
> I am a newbie with Python n Django programming. Can somebody tell me some
> easy methods for passing the Json data to the html page as arguments. I have
> the Json converted data stored in a variable. Now need to print those data
> in html.  while searching found some methods like using eval() in Ajax. But
> i cudnt work it out. Can somebody tel me some other methods with some
> examples.
>
> --
> Regards,
> Rav
>

Try javascript with jquery library

http://docs.jquery.com/Ajax/jQuery.getJSON


-- 
Simo

- Registered Linux User #395060

- Software is like sex, it is better when it is free  --> Linus B. Torvalds

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



Passing JSON data

2010-06-02 Thread ravi krishna
Hi,
I am a newbie with Python n Django programming. Can somebody tell me some
easy methods for passing the Json data to the html page as arguments. I have
the Json converted data stored in a variable. Now need to print those data
in html.  while searching found some methods like using eval() in Ajax. But
i cudnt work it out. Can somebody tel me some other methods with some
examples.

-- 
Regards,
Rav!

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



Re: want to convert object to json data.

2010-02-09 Thread bruno desthuilliers
On Feb 9, 10:40 am, chiranjeevi muttoju <chiru.bt...@gmail.com> wrote:
> hi waine,
> Thanks for ur reply. i got that. is there is any way to parse regular class
> objects(not model objects) to json data..

As documented, Django's json serialization is done using a bundled
version of simplejson, which is documented here:
http://simplejson.googlecode.com/svn/tags/simplejson-2.0.9/docs/index.html

As a side note, in Python, classes are actually objects too, so "class
object" usually refers to an object of type 'class'. What you're
referring to as 'class objects' are usually known as 'class
instances', or just 'objects' (since 1/ everything is an object, and
2/ all objects are instances of their class).

Also - and while the distinction indeed made sense in the current
context -, "model objects" (instances of Model's subclasses) ARE
actually "regular" python objects !-)

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



Re: want to convert object to json data.

2010-02-09 Thread chiranjeevi muttoju
hi waine,
Thanks for ur reply. i got that. is there is any way to parse regular class
objects(not model objects) to json data.. if u know please reply.

On Tue, Feb 9, 2010 at 12:17 PM, Wayne Koorts <wkoo...@gmail.com> wrote:

> > I want to convert a given regular object to json object. i.e. I want
> > to create a function which takes the class object as parameter and it
> > should return the json object.
>
> Have a look at the built-in Django "serializers" module:
>
>
> http://docs.djangoproject.com/en/dev/topics/serialization/#topics-serialization
>
> Regards,
> Wayne
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Thanks and regards,
chiranjeevi.muttoju

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



Re: want to convert object to json data.

2010-02-08 Thread Wayne Koorts
> I want to convert a given regular object to json object. i.e. I want
> to create a function which takes the class object as parameter and it
> should return the json object.

Have a look at the built-in Django "serializers" module:

http://docs.djangoproject.com/en/dev/topics/serialization/#topics-serialization

Regards,
Wayne

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



want to convert object to json data.

2010-02-08 Thread chiranjeevi.muttoju
Hi all,
I want to convert a given regular object to json object. i.e. I want
to create a function which takes the class object as parameter and it
should return the json object.
If anybody know please help me how to approach to get this.

Thanks and regards,
--chiranjeevi

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



Re: import json data into my django app

2010-01-17 Thread Bayuadji
if I were you,
I also will create a django command to call the utility,
it much easier that way.

-djibon-

On Mon, Jan 18, 2010 at 7:20 AM, nek4life <nek4l...@gmail.com> wrote:
> On Jan 17, 4:58 pm, lance <lan...@gmail.com> wrote:
>> Python/Django newbie question:
>>
>> I need to create a cron job that fetches json data from a URL, parses
>> it (presumably using simplejson) and then load the data into my
>> database using the Django models I've defined.
>>
>> I'm having trouble finding any tips, examples, or documentation on how
>> to do this... any help is greatly appreciated.
>
> I did something similar using the delicious api and elementtree to
> parse the data.
>
> First I created a module called utils.py in my application package and
> wrote a script for grabbing the url, parsing the data and updating the
> database.  Then I created another script called cron.py to run the
> utils.py every so often.  In the cron script you'll have to set your
> environmental variables for your project like so.
>
> import os
> import sys
> import site
>
> site.addsitedir('/opt/pythonenv/example.com/lib/python2.5/site-
> packages') # virtual environment
> sys.path.append('/var/www/vhosts/example.com/') # project location
> os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings' # settings
> file
>
> # import your module and then call it
>
> As far as using simplejson goes I haven't used it before.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>



-- 
--
http://www.tumbletooth.org
my linkedin profile : http://www.linkedin.com/in/bayuadji
--
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: import json data into my django app

2010-01-17 Thread nek4life
On Jan 17, 4:58 pm, lance <lan...@gmail.com> wrote:
> Python/Django newbie question:
>
> I need to create a cron job that fetches json data from a URL, parses
> it (presumably using simplejson) and then load the data into my
> database using the Django models I've defined.
>
> I'm having trouble finding any tips, examples, or documentation on how
> to do this... any help is greatly appreciated.

I did something similar using the delicious api and elementtree to
parse the data.

First I created a module called utils.py in my application package and
wrote a script for grabbing the url, parsing the data and updating the
database.  Then I created another script called cron.py to run the
utils.py every so often.  In the cron script you'll have to set your
environmental variables for your project like so.

import os
import sys
import site

site.addsitedir('/opt/pythonenv/example.com/lib/python2.5/site-
packages') # virtual environment
sys.path.append('/var/www/vhosts/example.com/') # project location
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings' # settings
file

# import your module and then call it

As far as using simplejson goes I haven't used it before.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




import json data into my django app

2010-01-17 Thread lance
Python/Django newbie question:

I need to create a cron job that fetches json data from a URL, parses
it (presumably using simplejson) and then load the data into my
database using the Django models I've defined.

I'm having trouble finding any tips, examples, or documentation on how
to do this... any help is greatly appreciated.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: HTML Escaping JSON data?

2008-06-17 Thread John

If the part of the page being changed is complex, the easiest way to
do this is to call render_to_response as usual, but with the template
containing only a  instead of a full HTML page. Handle any
escaping needed in the template.

If you only want to update the text without adding any markup, use
jQuery.fn.text instead of jQuery.fn.html.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: HTML Escaping JSON data?

2008-06-16 Thread Knifa

I'll try explain a little better, then.

I'm trying to make a Quote Database, and trying to make it so
switching between pages uses AJAX, loading them without refreshing. I
grab the Quote objects and serialize them to JSON so jQuery can read
it. Everything works fine, but the the quote field which contains the
actual quote does not have HTML characters such as < and > changed
into HTML entities which allows people to use HTML in quotes which I
don't want.
The form for entering quotes is from a ModelForm, which as far as I
can tell, doesn't escape HTML characters when you validate and save
it.

I've come accross cgi.encode, which works, but I don't feel it's the
right way to do what I'm doing.

On Jun 16, 5:59 pm, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
> What exactly are you trying to do?  Are you worried about people entering
> html into the form fields and having that saved to the database?  If so,
> Django's ORM escapes this for you when saving to the DB.  you can use
> jQuery's ajax functions to submit the form, and do normal form validation
> with newforms and it will be escaped when saving to the DB.  If there is
> something else you are concerned about or trying to do,  a bit more
> information may result in better responses.
> hth,
> -richard
>
> On 6/16/08, Knifa <[EMAIL PROTECTED]> wrote:
>
>
>
> > Err, nevermind that actually. It didn't seem to work.
>
> > By escaping I mean like turning < into  and > into  etc like
> > the "escape" filter does.
>
> > On Jun 16, 5:22 pm, Knifa <[EMAIL PROTECTED]> wrote:
> > > Oh damn, I should have probably looked around a bit more, heh. I'm not
> > > really used to JS yet.
>
> > > Thanks very much!
>
> > > On Jun 16, 5:09 pm, joshuajonah <[EMAIL PROTECTED]> wrote:
>
> > > > I'm not really catching what you're doing here. You want to escape
> > > > html with javascript? Just use escape()
>
> > > > On Jun 16, 11:31 am, Knifa <[EMAIL PROTECTED]> wrote:
>
> > > > > Hello there.
>
> > > > > I'm using Serialization with JSON to pass data to jQuery. Everything
> > > > > is working fine, except that the data for the fields of my model are
> > > > > not escaped, allowing people to use HTML on my app. There isn't a
> > > > > function as such in jQuery to do this (and I'm unsure if there is a
> > > > > built in Javascript one) so I'm assuming I have to do this serverside
> > > > > some how but i'm not really sure what to do.
>
> > > > > Any ideas would be greatly appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: HTML Escaping JSON data?

2008-06-16 Thread joshuajonah

Exactly, it sounds like there is a smarter way to do what your
attempting here.

On Jun 16, 12:59 pm, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
> What exactly are you trying to do?  Are you worried about people entering
> html into the form fields and having that saved to the database?  If so,
> Django's ORM escapes this for you when saving to the DB.  you can use
> jQuery's ajax functions to submit the form, and do normal form validation
> with newforms and it will be escaped when saving to the DB.  If there is
> something else you are concerned about or trying to do,  a bit more
> information may result in better responses.
> hth,
> -richard
>
> On 6/16/08, Knifa <[EMAIL PROTECTED]> wrote:
>
>
>
> > Err, nevermind that actually. It didn't seem to work.
>
> > By escaping I mean like turning < into  and > into  etc like
> > the "escape" filter does.
>
> > On Jun 16, 5:22 pm, Knifa <[EMAIL PROTECTED]> wrote:
> > > Oh damn, I should have probably looked around a bit more, heh. I'm not
> > > really used to JS yet.
>
> > > Thanks very much!
>
> > > On Jun 16, 5:09 pm, joshuajonah <[EMAIL PROTECTED]> wrote:
>
> > > > I'm not really catching what you're doing here. You want to escape
> > > > html with javascript? Just use escape()
>
> > > > On Jun 16, 11:31 am, Knifa <[EMAIL PROTECTED]> wrote:
>
> > > > > Hello there.
>
> > > > > I'm using Serialization with JSON to pass data to jQuery. Everything
> > > > > is working fine, except that the data for the fields of my model are
> > > > > not escaped, allowing people to use HTML on my app. There isn't a
> > > > > function as such in jQuery to do this (and I'm unsure if there is a
> > > > > built in Javascript one) so I'm assuming I have to do this serverside
> > > > > some how but i'm not really sure what to do.
>
> > > > > Any ideas would be greatly appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: HTML Escaping JSON data?

2008-06-16 Thread Richard Dahl
What exactly are you trying to do?  Are you worried about people entering
html into the form fields and having that saved to the database?  If so,
Django's ORM escapes this for you when saving to the DB.  you can use
jQuery's ajax functions to submit the form, and do normal form validation
with newforms and it will be escaped when saving to the DB.  If there is
something else you are concerned about or trying to do,  a bit more
information may result in better responses.
hth,
-richard


On 6/16/08, Knifa <[EMAIL PROTECTED]> wrote:
>
>
> Err, nevermind that actually. It didn't seem to work.
>
> By escaping I mean like turning < into  and > into  etc like
> the "escape" filter does.
>
> On Jun 16, 5:22 pm, Knifa <[EMAIL PROTECTED]> wrote:
> > Oh damn, I should have probably looked around a bit more, heh. I'm not
> > really used to JS yet.
> >
> > Thanks very much!
> >
> > On Jun 16, 5:09 pm, joshuajonah <[EMAIL PROTECTED]> wrote:
> >
> > > I'm not really catching what you're doing here. You want to escape
> > > html with javascript? Just use escape()
> >
> > > On Jun 16, 11:31 am, Knifa <[EMAIL PROTECTED]> wrote:
> >
> > > > Hello there.
> >
> > > > I'm using Serialization with JSON to pass data to jQuery. Everything
> > > > is working fine, except that the data for the fields of my model are
> > > > not escaped, allowing people to use HTML on my app. There isn't a
> > > > function as such in jQuery to do this (and I'm unsure if there is a
> > > > built in Javascript one) so I'm assuming I have to do this serverside
> > > > some how but i'm not really sure what to do.
> >
> > > > Any ideas would be greatly appreciated.
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: HTML Escaping JSON data?

2008-06-16 Thread joshuajonah

This should work: 
http://discuss.fogcreek.com/dotnetquestions/default.asp?cmd=show=5015

On Jun 16, 12:26 pm, Knifa <[EMAIL PROTECTED]> wrote:
> Err, nevermind that actually. It didn't seem to work.
>
> By escaping I mean like turning < into  and > into  etc like
> the "escape" filter does.
>
> On Jun 16, 5:22 pm, Knifa <[EMAIL PROTECTED]> wrote:
>
> > Oh damn, I should have probably looked around a bit more, heh. I'm not
> > really used to JS yet.
>
> > Thanks very much!
>
> > On Jun 16, 5:09 pm, joshuajonah <[EMAIL PROTECTED]> wrote:
>
> > > I'm not really catching what you're doing here. You want to escape
> > > html with javascript? Just use escape()
>
> > > On Jun 16, 11:31 am, Knifa <[EMAIL PROTECTED]> wrote:
>
> > > > Hello there.
>
> > > > I'm using Serialization with JSON to pass data to jQuery. Everything
> > > > is working fine, except that the data for the fields of my model are
> > > > not escaped, allowing people to use HTML on my app. There isn't a
> > > > function as such in jQuery to do this (and I'm unsure if there is a
> > > > built in Javascript one) so I'm assuming I have to do this serverside
> > > > some how but i'm not really sure what to do.
>
> > > > Any ideas would be greatly appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: HTML Escaping JSON data?

2008-06-16 Thread Knifa

Err, nevermind that actually. It didn't seem to work.

By escaping I mean like turning < into  and > into  etc like
the "escape" filter does.

On Jun 16, 5:22 pm, Knifa <[EMAIL PROTECTED]> wrote:
> Oh damn, I should have probably looked around a bit more, heh. I'm not
> really used to JS yet.
>
> Thanks very much!
>
> On Jun 16, 5:09 pm, joshuajonah <[EMAIL PROTECTED]> wrote:
>
> > I'm not really catching what you're doing here. You want to escape
> > html with javascript? Just use escape()
>
> > On Jun 16, 11:31 am, Knifa <[EMAIL PROTECTED]> wrote:
>
> > > Hello there.
>
> > > I'm using Serialization with JSON to pass data to jQuery. Everything
> > > is working fine, except that the data for the fields of my model are
> > > not escaped, allowing people to use HTML on my app. There isn't a
> > > function as such in jQuery to do this (and I'm unsure if there is a
> > > built in Javascript one) so I'm assuming I have to do this serverside
> > > some how but i'm not really sure what to do.
>
> > > Any ideas would be greatly appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: HTML Escaping JSON data?

2008-06-16 Thread Knifa

Oh damn, I should have probably looked around a bit more, heh. I'm not
really used to JS yet.

Thanks very much!

On Jun 16, 5:09 pm, joshuajonah <[EMAIL PROTECTED]> wrote:
> I'm not really catching what you're doing here. You want to escape
> html with javascript? Just use escape()
>
> On Jun 16, 11:31 am, Knifa <[EMAIL PROTECTED]> wrote:
>
> > Hello there.
>
> > I'm using Serialization with JSON to pass data to jQuery. Everything
> > is working fine, except that the data for the fields of my model are
> > not escaped, allowing people to use HTML on my app. There isn't a
> > function as such in jQuery to do this (and I'm unsure if there is a
> > built in Javascript one) so I'm assuming I have to do this serverside
> > some how but i'm not really sure what to do.
>
> > Any ideas would be greatly appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: HTML Escaping JSON data?

2008-06-16 Thread joshuajonah

I'm not really catching what you're doing here. You want to escape
html with javascript? Just use escape()

On Jun 16, 11:31 am, Knifa <[EMAIL PROTECTED]> wrote:
> Hello there.
>
> I'm using Serialization with JSON to pass data to jQuery. Everything
> is working fine, except that the data for the fields of my model are
> not escaped, allowing people to use HTML on my app. There isn't a
> function as such in jQuery to do this (and I'm unsure if there is a
> built in Javascript one) so I'm assuming I have to do this serverside
> some how but i'm not really sure what to do.
>
> Any ideas would be greatly appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



HTML Escaping JSON data?

2008-06-16 Thread Knifa

Hello there.

I'm using Serialization with JSON to pass data to jQuery. Everything
is working fine, except that the data for the fields of my model are
not escaped, allowing people to use HTML on my app. There isn't a
function as such in jQuery to do this (and I'm unsure if there is a
built in Javascript one) so I'm assuming I have to do this serverside
some how but i'm not really sure what to do.

Any ideas would be greatly appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---