会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask高级 258楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask视图高级 260楼

blueprint.zip

老师可以看看问题吗

Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask视图高级 261楼

TypeError

TypeError: one of the hex, bytes, bytes_le, fields, or int arguments must be given

Traceback (most recent call last)

  • File "/Users/xulei/python_env/flask_env/lib/python3.8/site-packages/flask/app.py", line 2548, in __call__

    return self.wsgi_app(environ, start_response)
  • File "/Users/xulei/python_env/flask_env/lib/python3.8/site-packages/flask/app.py", line 2528, in wsgi_app

    response = self.handle_exception(e)
  • File "/Users/xulei/python_env/flask_env/lib/python3.8/site-packages/flask/app.py", line 2525, in wsgi_app

    response = self.full_dispatch_request()
  • File "/Users/xulei/python_env/flask_env/lib/python3.8/site-packages/flask/app.py", line 1822, in full_dispatch_request

    rv = self.handle_user_exception(e)
  • File "/Users/xulei/python_env/flask_env/lib/python3.8/site-packages/flask/app.py", line 1820, in full_dispatch_request

    rv = self.dispatch_request()
  • File "/Users/xulei/python_env/flask_env/lib/python3.8/site-packages/flask/app.py", line 1796, in dispatch_request

    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  • File "/Users/xulei/Downloads/Flask_code/Flask高级/24_wtf常用的验证器.py", line 22, in register

    if form.validate():
  • File "/Users/xulei/python_env/flask_env/lib/python3.8/site-packages/wtforms/form.py", line 329, in validate

    return super().validate(extra)
  • File "/Users/xulei/python_env/flask_env/lib/python3.8/site-packages/wtforms/form.py", line 146, in validate

    if not field.validate(self, extra):
  • File "/Users/xulei/python_env/flask_env/lib/python3.8/site-packages/wtforms/fields/core.py", line 242, in validate

    stop_validation = self._run_validation_chain(form, chain)
  • File "/Users/xulei/python_env/flask_env/lib/python3.8/site-packages/wtforms/fields/core.py", line 262, in _run_validation_chain

    validator(form, self)
  • File "/Users/xulei/python_env/flask_env/lib/python3.8/site-packages/wtforms/validators.py", line 555, in __call__

    uuid.UUID(field.data)
  • File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/uuid.py", line 163, in __init__

    raise TypeError('one of the hex, bytes, bytes_le, fields, '
TypeError: one of the hex, bytes, bytes_le, fields, or int arguments must be given遇到这种报错 是什么意思

Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask高级 262楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask高级 263楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask视图基础和URL 264楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask之Jinja2模版 265楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask数据库 267楼

SharedScreenshot1.jpg

SharedScreenshot.jpg

老师,麻烦看看我的代码,我的代码到网页运行以后输入用户名和密码然后登录,会跳到初始状态,不显示登录成功,输入错误也会跳到初始状态。下面是源代码:

from flask import Flask,request,render_template
from flask.views import MethodView

app = Flask(__name__)

# @app.route('/login/',methods=['GET','POST'])
# def login():
#     if request.method == 'GET':
#         return render_template('login05.html')
#     elif request.method == 'POST':
#         uname = request.form.get('uname')
#         pwd = request.form.get('pwd')
#         print(uname)
#         print(pwd)
#         if uname == 'zs' and pwd == '123':
#             return '登录成功'
#         else:
#             return render_template('login05.html')

class LoginView(MethodView):
    def get(self):
        return render_template('login05.html')
    def post(self):
        uname = request.form.get['uname']
        pwd = request.form.get['pwd']
        print(uname)
        print(pwd)
        if uname == 'zs' and pwd == '123':
            return "登录成功!"
        else:
            return render_template('login05.html',msg='用户名或密码错误')

app.add_url_rule('/login/',view_func=LoginView.as_view('login'))

if __name__ == '__main__':
    app.run(debug=True)
    
下面是html05.html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
</head>

<body>

    <h2>Login</h2>
    <form action="/login/" methods='POST'>
        <table>
            <tr>
                <td>用户名:</td>
                <td><input type="text" name="uname"></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" name="pwd"></td>
            </tr>
            <tr>
                <td><input type="submit" value="登录"></td>
            </tr>
        </table>
    </form>
    <span style="color: red;">{{ msg }}</span>
</body>

</html>


Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask视图高级 268楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask数据库 269楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask数据库 270楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637