嗨,我正在运行此代码时得到重复的条目,但不能确定为什么会发生以下代码
def match_domain(request):
user_domain_array = ['rohit@ghrix.com','rahul@ghrix.com','rishi@ghrix.com']
getclientdomain = client_domain.objects.all()
for i in getclientdomain:
for u in user_domain_array :
if i.client_domain in u :
saveuser = User(email = u)
saveuser.save()
#return HttpResponse(u)
else :
return HttpResponse("no")
getclientdomain在数据库中的数据库中具有一个条目,其值为 ghrix.com ,它将数组中的第一个元素插入到数据库中,然后引发重复
请告诉我我在哪里做错了。
最佳答案
您可以尝试以下方法:
每次也为用户名字段发送不同的内容,因为查看保存查询时,您仅插入电子邮件,所以我认为用户名字段必须为空。因此,第一次插入第一行,但是第二次不插入,并给出重复的输入错误。
关于python - 重复输入错误Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19175707/