鱼C论坛

 找回密码
 立即注册
查看: 775|回复: 3

[已解决]麻烦大佬看看这个报错

[复制链接]
发表于 2023-6-16 14:05:35 | 显示全部楼层 |阅读模式
10鱼币

本帖最后由 tengke 于 2023-6-16 11:57 编辑


class Logina(forms.Form):
    username  = forms.CharField(label="用户名",
                                widget=forms.TextInput(attrs={"class":"form-control","maxlength":"12","placeholder":"请输入用户名","autocomplete":"off"}))
    password =  forms.CharField(label="密码",
                                widget=forms.PasswordInput(attrs={"class":"form-control","maxlength":"12","placeholder":"请输入密码","autocomplete":"off"}))
    yzm = forms.CharField(label="验证码",
                          widget=forms.PasswordInput(attrs={"class": "form-control", "maxlength": "12", "placeholder": "验证码","autocomplete": "off"}))
    def clean(self):
        cleaned_data = super().clean()
        pwd = md5(cleaned_data.get("password"))
        print(pwd,"clean的密码")
        cleaned_data["password"] = pwd
        return cleaned_data

____
def yzm(request):
    img,code_staing = check_code()
    print(code_staing)
    #写入到自己的session中
    request.session['image_code']=code_staing
    #图片60秒超时
    request.session.set_expiry(60)
    stream = BytesIO()
    img.save(stream, 'png')
    # stream.getvalue()
    return  HttpResponse(stream.getvalue())

_________
def login(request):
    if request.method == "GET":
        form = Logina()
        return render(request,"login.html",{"form":form})
    form = Logina(data=request.POST)
    print(form.is_valid(),"formis")
    print(form.errors.as_json())
    # print(form,"from 字段属性")
    if form.is_valid():
        # print(form.cleaned_data)
        # pd = models.admin.objects.filter(username=form.cleaned_data["username"],password=form.cleaned_data["password"])
        pd = models.admin.objects.filter(**form.cleaned_data).first()
        print(form.cleaned_data,"cleaned_data")
        print(form.cleaned_data['yzm'])


    print(form.errors.as_json())这个打印出来的是
{"yzm": [{"message": "\u8fd9\u4e2a\u5b57\u6bb5\u662f\u5fc5\u586b\u9879\u3002", "code": "required"}]}

麻烦大佬看看这个
最佳答案
2023-6-16 14:05:36
tengke 发表于 2023-6-16 18:12
麻烦来个人评论一下 解决了


解决了就行

给我最佳答案吧

最佳答案

查看完整内容

解决了就行 给我最佳答案吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-6-16 14:05:36 | 显示全部楼层    本楼为最佳答案   
tengke 发表于 2023-6-16 18:12
麻烦来个人评论一下 解决了


解决了就行

给我最佳答案吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-6-16 18:12:36 | 显示全部楼层
麻烦来个人评论一下 解决了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-6-17 06:11:41 | 显示全部楼层
应该是要使用json.loads
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-3 11:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表