本文整理汇总了Python中user.models.User.random方法的典型用法代码示例。如果您正苦于以下问题:Python User.random方法的具体用法?Python User.random怎么用?Python User.random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user.models.User
的用法示例。
在下文中一共展示了User.random方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import random [as 别名]
def register(request):
if request.method == "POST":
rst = json.loads(request.body.decode("utf-8"))
uf = UserForm(rst)
if uf.is_valid():
#检测用户是否存在
checkUser = User.objects.filter(email__exact = uf.cleaned_data['email']).first()
if checkUser:
data = {}
data["status"] = 'error'
data['msg'] = "此Email账户已存在"
return HttpResponse(json.dumps(data), content_type="application/json")
user = User()
user.username = uf.cleaned_data['username']
pwd = (uf.cleaned_data['password'] + keyPwd).encode("utf-8")
user.password = hashlib.sha1(pwd).hexdigest()
user.qq = uf.cleaned_data['qq']
user.email = uf.cleaned_data['email']
user.random = ''.join(random.sample(string.ascii_letters + string.digits, 10))
user.save()
data = {}
data["status"] = 'success'
data['msg'] = ""
return HttpResponse(json.dumps(data), content_type="application/json")
else:
data = {}
data["status"] = 'error'
data['msg'] = "Illegal post"
return HttpResponse(json.dumps(data), content_type="application/json")
else:
data = {}
data["status"] = 'error'
data['msg'] = "Only post method"
return HttpResponse(json.dumps(data), content_type="application/json")