根据键值取得对象,如果不存在则创建新对象返回。defaults 参数提供给创建对象时使用。

f, created = Foo.objects.get_or_create(id=id,
    defaults
={'attr1'123'attr2'"hello"})
if created:
    
# 新建的逻辑
else:
    
# Django 代码片断收集(持续更新)

获取客户端信息:

ip = request.META['REMOTE_ADDR']
user_agent 
= request.META['HTTP_USER_AGENT'

相关文章:

  • 2021-08-05
  • 2018-07-17
  • 2021-10-20
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2021-10-18
猜你喜欢
  • 2021-07-07
  • 2021-06-07
  • 2022-01-18
  • 2021-11-25
  • 2022-12-23
  • 2021-08-12
相关资源
相似解决方案