我使用的是redis 6.2版
这是我正在研究的观点:
elif request.method == 'POST':
user_key = request.user
bid_price = request.POST.get('bid')
retrieve_product = request.POST.get('product.id')
product_key = Product.objects.get(id=retrieve_product)
minimum_price = product_key.base_price
if float(bid_price) >= minimum_price:
if redis_instance.hexists(product_key, "highest_bid"):
hb_value = redis_instance.hget(product_key, "highest_bid")
else:
redis_instance.hset(product_key, "highest_bid", bid_price)
hb_value = bid_price
if bid_price > hb_value:
redis_instance.hset(product_key, user_key, bid_price)
redis_instance.hset(product_key, "highest_bid", bid_price)
messages.info('Your bid was successfully processed')
return HttpResponse('successfully uploaded')
else:
return HttpResponse('Your bid is lower than current highest bid')
else:
return HttpResponse('Your bid is lower than minimum price')
本无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无无“好的,好的”
相反,这是模型:
class Product(models.Model):
name = models.CharField(max_length=200, null=True)
base_price = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
digital = models.BooleanField(default=False, null=True, blank=True)
start_date = models.DateTimeField(default=timezone.now)
end_date = models.DateTimeField(default=one_day_hence)
bidding_finished = models.BooleanField(default=False)
def __str__(self):
return self.name
错误回溯:
Traceback (most recent call last): File
"C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\wsgiref\handlers.py",
line 138, in run
self.finish_response() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\wsgiref\handlers.py",
line 196, in finish_response
self.close() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\servers\basehttp.py",
line 114, in close
super().close() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\wsgiref\simple_server.py",
line 38, in close
SimpleHandler.close(self) File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\wsgiref\handlers.py",
line 335, in close
self.result.close() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\http\response.py",
line 253, in close
signals.request_finished.send(sender=self._handler_class) File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\dispatch\dispatcher.py",
line 173, in send
return [ File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\dispatch\dispatcher.py",
line 174, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named)) File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\__init__.py",
line 57, in close_old_connections
conn.close_if_unusable_or_obsolete() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\base\base.py",
line 525, in close_if_unusable_or_obsolete
self.close() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\asyncio.py",
line 26, in inner
return func(*args, **kwargs) File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\sqlite3\base.py",
line 261, in close
if not self.is_in_memory_db(): File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\sqlite3\base.py",
line 380, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict['NAME']) File
"C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\sqlite3\creation.py",
line 12, in is_in_memory_db
return database_name == ':memory:' or 'mode=memory' in database_name TypeError: argument of type 'WindowsPath' is not
iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\socketserver.py",
line 650, in process_request_thread
self.finish_request(request, client_address) File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\socketserver.py",
line 360, in finish_request
self.RequestHandlerClass(request, client_address, self) File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\socketserver.py",
line 720, in __init__
self.handle() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\servers\basehttp.py",
line 174, in handle
self.handle_one_request() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\servers\basehttp.py",
line 197, in handle_one_request
handler.run(self.server.get_app()) File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\wsgiref\handlers.py",
line 145, in run
self.handle_error() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\servers\basehttp.py",
line 119, in handle_error
super().handle_error() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\wsgiref\handlers.py",
line 382, in handle_error
self.finish_response() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\wsgiref\handlers.py",
line 184, in finish_response
self.write(data) File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\wsgiref\handlers.py",
line 288, in write
self.send_headers() File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\wsgiref\handlers.py",
line 345, in send_headers
if not self.origin_server or self.client_is_modern(): File "C:\Users\alber\AppData\Local\Programs\Python\Python38\lib\wsgiref\handlers.py",
line 358, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9' TypeError: 'NoneType' object is not subscriptable
根据文章标题中的错误消息(而不是文章中的回溯),您的问题是使用包含
Product
模型对象的product_key
变量调用Redis.hexists()
、Redis.hget()
和Redis.hset()
方法相反,使用Redis键的字符串值,例如
str(product_key.id)
您还需要为
user_key
执行类似的操作相关问题 更多 >
编程相关推荐