Javascript 当我试图在django中更新表单时,遇到了这种类型的问题

Javascript 当我试图在django中更新表单时,遇到了这种类型的问题,javascript,php,python,django,Javascript,Php,Python,Django,我将此类型值存储在DB中: 输入: { "PatientProfile__is_recruiter": "1", "PatientProfile__partner": "FMCS", "PatientProfile__health_insurance_provider": "MILITARY/VA", "PatientProfile__has_medical_home": "0", "PatientProfile__medical_history_

我将此类型值存储在DB中:

输入:

{
    "PatientProfile__is_recruiter": "1", 
    "PatientProfile__partner": "FMCS", 
    "PatientProfile__health_insurance_provider": "MILITARY/VA", 
    "PatientProfile__has_medical_home": "0", 
    "PatientProfile__medical_history_heart_disease": "0", 
    "PatientProfile__medical_history_hypertension": "0", 
    "data_model_name": [
        "PatientProfile"
    ]
}
当我尝试更新时以及更新后,我发现相同的结果如下:

{
    "PatientProfile__is_recruiter": "1", 
    "PatientProfile__partner": "FMCS", 
    "PatientProfile__health_insurance_provider": "MILITARY/VA", 
    "PatientProfile__has_medical_home": "0", 
    "PatientProfile__medical_history_heart_disease": "0", 
    "PatientProfile__medical_history_hypertension": "0", 
    "data_model_name": [
        "PatientProfile"
    ]
}
如果我不更新此代码并提取到db并尝试执行。我没有得到任何错误。 当我在更新后尝试执行此代码时。我发现以下定义错误:

回溯(最近一次呼叫最后一次):

get_响应中的第111行“
File”/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py”
响应=回调(请求,*回调参数,**回调参数)
文件“/usr/local/lib/python2.6/dist packages/django/contrib/auth/decorators.py”,第23行,在包装视图中
返回视图功能(请求,*args,**kwargs)
文件“/home/ubuntu/django apps/project\u name/。/project\u name/apps/accounts/decorators.py”,第44行,位于内部装饰器中
返回函数(请求、*args、**kwargs)
文件“/home/ubuntu/django apps/project\u name/。/project\u name/apps/reports/views.py”,第97行,在hiv\u report\u new中
返回表格。获取表格(pk)
文件“/home/ubuntu/django apps/project\u name/。/project\u name/apps/reports/forms.py”,第454行,在get\u itable中
自定义_data=ast.literal_eval(报告[0]['query'])
文件“/usr/lib/python2.6/ast.py”,第49行,文本形式
node_或_string=parse(node_或_string,mode='eval')
文件“/usr/lib/python2.6/ast.py”,第37行,在parse中
返回编译(expr、文件名、模式、仅PyCF\u AST)
文件“”,第1行
{
^
SyntaxError:无效语法

请使用
json
dict
list
存储在
db

例如

储存时

obj = json.dumps("{
    'PatientProfile__is_recruiter': '1', 
    'PatientProfile__partner': 'FMCS', 
    'PatientProfile__health_insurance_provider': 'MILITARY/VA', 
    'PatientProfile__has_medical_home': '0', 
    'PatientProfile__medical_history_heart_disease': '0', 
    'PatientProfile__medical_history_hypertension': '0', 
    'data_model_name': [
        'PatientProfile'
    ]
}")
并存储json obj,即obj

在检索时使用

json.loads
因此,您将获得以前在db中保存的原样


:)

存储时使用json.dumps:

obj = json.dumps("{
'PatientProfile__is_recruiter': '1', 
'PatientProfile__partner': 'FMCS', 
'PatientProfile__health_insurance_provider': 'MILITARY/VA', 
'PatientProfile__has_medical_home': '0', 
'PatientProfile__medical_history_heart_disease': '0', 
'PatientProfile__medical_history_hypertension': '0', 
'data_model_name': ['PatientProfile']
}")
在检索时,您有两个选项,即

例如:

>>>simplejson.loads('{"x":"y"}') 
{'x': 'y'}


>>> json.loads('{"x":"y"}') 
{u'x': u'y'} 
i、 如果字符串是ASCII,simplejson将返回bytestrings(返回
unicode对象),而json总是返回unicode对象。

如果问题纯粹是关于Python的,那么添加随机Javascript和PHP标记将无助于回答您的问题,事实就是如此。在任何情况下,您肯定需要显示导致错误的forms.py部分。
>>>simplejson.loads('{"x":"y"}') 
{'x': 'y'}


>>> json.loads('{"x":"y"}') 
{u'x': u'y'}