简体   繁体   English

如何使用相同的键将python字典替换为QueryDict

[英]How to replace python dictionary to QueryDict with same key

I have a QueryDict from HttpRequest (request.POST) and I Have a new dictionary with same key.我有一个来自 HttpRequest (request.POST) 的 QueryDict 并且我有一个具有相同键的新字典。 How can I insert or replace my new dictionary to QueryDict.如何将我的新字典插入或替换为 QueryDict。 any help will be appreciated.任何帮助将不胜感激。

<QueryDict: {'csrfmiddlewaretoken': ['FEWFDFdcgfgrthBFFBDFBDF'], 'form-TOTAL_FORMS': ['13'], 'form-INITIAL_FORMS': ['0'], 'form-MIN_NUM_FORMS': ['0'], 'form-MAX_NUM_FORMS': ['1000'],
             'form-0-publish': ['05/28/2019'], 'form-0-cell': ['81'], 'form-0-cell_name': ['13a'], 'form-0-jam': ['07.00-08.00'], 'form-0-target': ['60'], 'form-0-model_name': [''], 'form-0-article_no': [''], 'form-0-input_qty': [''], 'form-0-cementing_qty': [''], 'form-0-perbaikan_qty': [''], 'form-0-b_grade_qty': [''], 'form-0-diff_manual_output': [''], 'form-0-scan_bungkus': [''], 'form-0-total_scan_bungkus': [''], 'form-0-manual_output_qty': [''], 'form-0-total_manual_output': [''], 'form-0-scan_pack_qty': ['10'], 'form-0-component_upper_qty': [''], 'form-0-total_scan_pack': [''], 'form-0-grand_total_qty': [''], 'form-0-diff_output_component_upper': [''], 'form-0-problem': [''], 'form-0-tot_prod_hours': [''], 'form-0-tot_prod_ot': [''], 'form-0-time_normal': [''], 'form-0-time_ot1': [''], 'form-0-time_ot2': [''], 'form-0-time_ot3': [''],
             'form-1-publish': ['05/28/2019'], 'form-1-cell': ['81'], 'form-1-cell_name': ['13a'], 'form-1-jam': ['07.00-08.00'], 'form-1-target': ['60'], 'form-1-model_name': [''], 'form-1-article_no': [''], 'form-1-input_qty': [''], 'form-1-cementing_qty': [''], 'form-1-perbaikan_qty': [''], 'form-1-b_grade_qty': [''], 'form-1-diff_manual_output': [''], 'form-1-scan_bungkus': [''], 'form-1-total_scan_bungkus': [''], 'form-1-manual_output_qty': [''], 'form-1-total_manual_output': [''], 'form-1-scan_pack_qty': ['20'], 'form-1-component_upper_qty': [''], 'form-1-total_scan_pack': [''], 'form-1-grand_total_qty': [''], 'form-1-diff_output_component_upper': [''], 'form-1-problem': [''], 'form-1-tot_prod_hours': [''], 'form-1-tot_prod_ot': [''], 'form-1-time_normal': [''], 'form-1-time_ot1': [''], 'form-1-time_ot2': [''], 'form-1-time_ot3': [''],
             'form-2-publish': ['05/28/2019'], 'form-2-cell': ['81'], 'form-2-cell_name': ['13a'], 'form-2-jam': ['07.00-08.00'], 'form-2-target': ['60'], 'form-2-model_name': [''], 'form-2-article_no': [''], 'form-2-input_qty': [''], 'form-2-cementing_qty': [''], 'form-2-perbaikan_qty': [''], 'form-2-b_grade_qty': [''], 'form-2-diff_manual_output': [''], 'form-2-scan_bungkus': [''], 'form-2-total_scan_bungkus': [''], 'form-2-manual_output_qty': [''], 'form-2-total_manual_output': [''], 'form-2-scan_pack_qty': ['10'], 'form-2-component_upper_qty': [''], 'form-2-total_scan_pack': [''], 'form-2-grand_total_qty': [''], 'form-2-diff_output_component_upper': [''], 'form-2-problem': [''], 'form-2-tot_prod_hours': [''], 'form-2-tot_prod_ot': [''], 'form-2-time_normal': [''], 'form-2-time_ot1': [''], 'form-2-time_ot2': [''], 'form-2-time_ot3': [''],

my_dict={'form-0-publish': ['05/28/2019'], 'form-0-cell': ['81'], 'form-0-cell_name': ['13a'], 'form-0-jam': ['07.00-08.00'], 'form-0-target': ['60'], 'form-0-model_name': [''], 'form-0-article_no': [''], 'form-0-input_qty': [''], 'form-0-cementing_qty': [''], 'form-0-perbaikan_qty': [''], 'form-0-b_grade_qty': [''], 'form-0-diff_manual_output': [''], 'form-0-scan_bungkus': [''], 'form-0-total_scan_bungkus': [''], 'form-0-manual_output_qty': [''], 'form-0-total_manual_output': [''], 'form-0-scan_pack_qty': ['10'], 'form-0-component_upper_qty': [''], 'form-0-total_scan_pack': [''], 'form-0-grand_total_qty': [''], 'form-0-diff_output_component_upper': [''], 'form-0-problem': [''], 'form-0-tot_prod_hours': ['40'], 'form-0-tot_prod_ot': [''], 'form-0-time_normal': ['0.25'], 'form-0-time_ot1': [''], 'form-0-time_ot2': [''], 'form-0-time_ot3': [''],
         'form-1-publish': ['05/28/2019'], 'form-1-cell': ['81'], 'form-1-cell_name': ['13a'], 'form-1-jam': ['07.00-08.00'], 'form-1-target': ['60'], 'form-1-model_name': [''], 'form-1-article_no': [''], 'form-1-input_qty': [''], 'form-1-cementing_qty': [''], 'form-1-perbaikan_qty': [''], 'form-1-b_grade_qty': [''], 'form-1-diff_manual_output': [''], 'form-1-scan_bungkus': [''], 'form-1-total_scan_bungkus': [''], 'form-1-manual_output_qty': [''], 'form-1-total_manual_output': [''], 'form-1-scan_pack_qty': ['20'], 'form-1-component_upper_qty': [''], 'form-1-total_scan_pack': [''], 'form-1-grand_total_qty': [''], 'form-1-diff_output_component_upper': [''], 'form-1-problem': [''], 'form-1-tot_prod_hours': ['40'], 'form-1-tot_prod_ot': [''], 'form-1-time_normal': ['0.5'], 'form-1-time_ot1': [''], 'form-1-time_ot2': [''], 'form-1-time_ot3': [''],
         'form-2-publish': ['05/28/2019'], 'form-2-cell': ['81'], 'form-2-cell_name': ['13a'], 'form-2-jam': ['07.00-08.00'], 'form-2-target': ['60'], 'form-2-model_name': [''], 'form-2-article_no': [''], 'form-2-input_qty': [''], 'form-2-cementing_qty': [''], 'form-2-perbaikan_qty': [''], 'form-2-b_grade_qty': [''], 'form-2-diff_manual_output': [''], 'form-2-scan_bungkus': [''], 'form-2-total_scan_bungkus': [''], 'form-2-manual_output_qty': [''], 'form-2-total_manual_output': [''], 'form-2-scan_pack_qty': ['10'], 'form-2-component_upper_qty': [''], 'form-2-total_scan_pack': [''], 'form-2-grand_total_qty': [''], 'form-2-diff_output_component_upper': [''], 'form-2-problem': [''], 'form-2-tot_prod_hours': ['40'], 'form-2-tot_prod_ot': [''], 'form-2-time_normal': ['0.25'], 'form-2-time_ot1': [''], 'form-2-time_ot2': [''], 'form-2-time_ot3': ['']}

#new QueryDict I want
<QueryDict: {'csrfmiddlewaretoken': ['FEWFDFdcgfgrthBFFBDFBDF'], 'form-TOTAL_FORMS': ['13'], 'form-INITIAL_FORMS': ['0'], 'form-MIN_NUM_FORMS': ['0'], 'form-MAX_NUM_FORMS': ['1000'], 
         'form-0-publish': ['05/28/2019'], 'form-0-cell': ['81'], 'form-0-cell_name': ['13a'], 'form-0-jam': ['07.00-08.00'], 'form-0-target': ['60'], 'form-0-model_name': [''], 'form-0-article_no': [''], 'form-0-input_qty': [''], 'form-0-cementing_qty': [''], 'form-0-perbaikan_qty': [''], 'form-0-b_grade_qty': [''], 'form-0-diff_manual_output': [''], 'form-0-scan_bungkus': [''], 'form-0-total_scan_bungkus': [''], 'form-0-manual_output_qty': [''], 'form-0-total_manual_output': [''], 'form-0-scan_pack_qty': ['10'], 'form-0-component_upper_qty': [''], 'form-0-total_scan_pack': [''], 'form-0-grand_total_qty': [''], 'form-0-diff_output_component_upper': [''], 'form-0-problem': [''], 'form-0-tot_prod_hours': ['40'], 'form-0-tot_prod_ot': [''], 'form-0-time_normal': ['0.25'], 'form-0-time_ot1': [''], 'form-0-time_ot2': [''], 'form-0-time_ot3': [''],
         'form-1-publish': ['05/28/2019'], 'form-1-cell': ['81'], 'form-1-cell_name': ['13a'], 'form-1-jam': ['07.00-08.00'], 'form-1-target': ['60'], 'form-1-model_name': [''], 'form-1-article_no': [''], 'form-1-input_qty': [''], 'form-1-cementing_qty': [''], 'form-1-perbaikan_qty': [''], 'form-1-b_grade_qty': [''], 'form-1-diff_manual_output': [''], 'form-1-scan_bungkus': [''], 'form-1-total_scan_bungkus': [''], 'form-1-manual_output_qty': [''], 'form-1-total_manual_output': [''], 'form-1-scan_pack_qty': ['20'], 'form-1-component_upper_qty': [''], 'form-1-total_scan_pack': [''], 'form-1-grand_total_qty': [''], 'form-1-diff_output_component_upper': [''], 'form-1-problem': [''], 'form-1-tot_prod_hours': ['40'], 'form-1-tot_prod_ot': [''], 'form-1-time_normal': ['0.5'], 'form-1-time_ot1': [''], 'form-1-time_ot2': [''], 'form-1-time_ot3': [''],
         'form-2-publish': ['05/28/2019'], 'form-2-cell': ['81'], 'form-2-cell_name': ['13a'], 'form-2-jam': ['07.00-08.00'], 'form-2-target': ['60'], 'form-2-model_name': [''], 'form-2-article_no': [''], 'form-2-input_qty': [''], 'form-2-cementing_qty': [''], 'form-2-perbaikan_qty': [''], 'form-2-b_grade_qty': [''], 'form-2-diff_manual_output': [''], 'form-2-scan_bungkus': [''], 'form-2-total_scan_bungkus': [''], 'form-2-manual_output_qty': [''], 'form-2-total_manual_output': [''], 'form-2-scan_pack_qty': ['10'], 'form-2-component_upper_qty': [''], 'form-2-total_scan_pack': [''], 'form-2-grand_total_qty': [''], 'form-2-diff_output_component_upper': [''], 'form-2-problem': [''], 'form-2-tot_prod_hours': ['40'], 'form-2-tot_prod_ot': [''], 'form-2-time_normal': ['0.25'], 'form-2-time_ot1': [''], 'form-2-time_ot2': [''], 'form-2-time_ot3': ['']

Why not use .dict() (version >= 1.4):为什么不使用.dict() (版本 >= 1.4):

print(request.POST.dict())

If your version < 1.4, do:如果您的版本 < 1.4,请执行以下操作:

print(dict(request.POST.iterlists()))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM