2013-04-29 2 views
1

я пытаюсь установить значение от Джанго сервера в моей JavaScript файлJava Script дает ошибку недопустимый синтаксис при попытке установить значение от Джанго сервера

views.py 
def convert(input): 
if isinstance(input, dict): 
return {convert(key): convert(value) for key, value in input.iteritems()} 
elif isinstance(input, list): 
return [convert(element) for element in input] 
elif isinstance(input, unicode): 
return input.encode('utf-8') 
else: 
return input 


@csrf_exempt 
def changebutton(request): 
ids = request.GET['id'] 

t = get_template('Jquerymobilechangofdetailbutton222.html') 
record = changeButton.objects(id = str(ids))[0] 

dictionary = record.to_mongo() 
if dictionary.has_key('_id'): 
dictionary['ids'] = dictionary['_id'] 
del dictionary['_id'] 
dictionary = convert(dictionary) 
print dictionary, "dict" 
html = t.render(Context(dictionary)) 
return HttpResponse(html) 


server log 
{'username': 'Alok', '_types': ['changeButton'], 
'ids': ObjectId('517e15f141d34226fc61525c'), 
'_cls': 'changeButton', 
'usergroup': ['user', 'admin'], 
'details':[{'_types': ['userdetails'], 'add2': 'ee', 'add1': 'dd', 'mname': 'bb', 'lname': 'cc', '_cls': 'userdetails', 'fname': 'aa'}]} dict 


HTML page 
<script> 
dict = {{usergroup}} 
console.log(dict) 
</script> 

проблема его подачи dict = [&#39;user&#39;, &#39;admin&#39;] и дает неверный синтаксис (из-за наличие &#39;) любая помощь была бы весьма признательна

ответ

Смежные вопросы