Local variable 'dict' referenced before assignment

problem description

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

< H1 > place an order < / H1 >

def post_order_place (request):

"""

apiid,symbol,timestamp
type: buy-limit/sell-limit
price:
quantity:
"""  
timestamp = create_timestamp()
data = dict(request.POST)
print(data)
print(data.items)

for key, value in request.POST.iteritems():
    if "price" in key:
        price[key] = value
    if "quantity" in key:
        quantity[key] = value
    if "type" in key:
        type[key] = value

price = data["price"]
quantity = data["quantity"]
type = data["type"]
print(price)
print(quantity)
print(type)

what result do you expect? What is the error message actually seen?

to solve the problem of error reporting, I did not use dict before defining the function, but dict (request.POST) reported an error
error message: UnboundLocalError: local variable "dict" referenced before assignment

Aug.11,2021

in the for loop, neither your price, quantity nor your type is initialized to dict, so you just use them as dict

for key, value in request.POST.iteritems():
    if 'price' in key:
        data['price'] = value
    if 'quantity' in key:
        data['quantity'] = value
    if 'type' in key:
        data['type'] = value
Menu