python - How to populate JSON dump from a form to a django template? -
i importing post
request form template.html
view.py
using
data=json.dumps(request.post)
the data @ view.py
in format:
{"5": "25", "4": "28", "6": "21"}
while running dictionary syntax on it, error pops data in string form. how convert dictionary? further, need populate 'key' , 'value' of dictionary template.
please me out?
try this:
>>> = '{"5": "25", "4": "28", "6": "21"}' >>> type(a) <type 'str'> >>> >>> import ast >>> x = ast.literal_eval(a) >>> type(x) <type 'dict'> >>> >>> x.keys() ['5', '4', '6'] >>> x.values() ['25', '28', '21']
Comments
Post a Comment