根据键值取得对象,如果不存在则创建新对象返回。defaults 参数提供给创建对象时使用。
f, created = Foo.objects.get_or_create(id=id,
defaults={'attr1': 123, 'attr2': "hello"})
if created:
# 新建的逻辑
else:
#
defaults={'attr1': 123, 'attr2': "hello"})
if created:
# 新建的逻辑
else:
#

获取客户端信息:
ip = request.META['REMOTE_ADDR']
user_agent = request.META['HTTP_USER_AGENT']
user_agent = request.META['HTTP_USER_AGENT']