我的views.py
中有以下方法。
def update_module(request):
rules =[]
data = QueryDict(request)
module_name = data.get('module_name')
module_description = data.get('description')
rule_ids = data.get('rule_ids')
rule_names = data.get('rule_names')
module_id = data.get('module_id')
if rule_ids is not None:
rule_ids = rule_ids.split(',')
if rule_ids and rule_id[0]:
rules = models.Rule.objects.filter(pk__in=rule_ids)
elif rule_names:
for rn in rule_names:
rule = models.Rule(name=rn, user=get_current_user(request))
rule.save()
rules.append(rule)
module = get_object_or_404(models.Module, pk=module_id)
if module_name is not None:
module.name = module_name
if module_description is not None:
module.description = module_description
if rules is not None:
for rule in rules:
module.rules.add(rule)
try:
module.save()
except Exception as e:
return HttpResponse(json.dumps({'error': e.message}))
return HttpResponse(json.dumps(module.to_json()), content_type='application/json')
我正在点击卷曲请求,如下所示。
curl -X PUT -data="module_name=rohit&description=sample&rule_ids=1,2,3&module_id=1" http://localhost:8000/module/
它引发了一个例外。
Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/rokumar/SiteAnalysisGit/Src/hct/hct/views.py" in module_handler
675. return update_module(request)
File "/Users/rokumar/SiteAnalysisGit/Src/hct/hct/views.py" in update_module
627. data = QueryDict(request)
File "/Library/Python/2.7/site-packages/django/http/request.py" in __init__
328. keep_blank_values=True):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urlparse.py" in parse_qsl
408. pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
Exception Type: AttributeError at /module/
Exception Value: 'WSGIRequest' object has no attribute 'split'
为什么分裂不会在字符串中重复。