[BUG] python class not support
See original GitHub issueclass IndexController: @app.get("/test") def test(self): return {"Hello": "IndexController"}
after app started, get http://127.0.0.1:8080/test
then the browser show message
{"detail":[{"loc":["query","self"],"msg":"field required","type":"value_error.missing"}]}
Want to support the formal API of classes
example :
from app.common.results import Results from app.lib.classy import route from app.lib.classy_plus import FlaskViewPlus, controller from app.lib.utils import validate, ignore_auth from app.service.user_service import UserService from app.web.validates.form import LoginForm, UpdatePwdForm
@controller(route_base=‘user’) class UserController(FlaskViewPlus): “”" 用户控制器相关 “”"
@route('/login', methods=['POST'])
@validate(LoginForm)
def login(self, loginForm=None):
"""
登录
:param loginForm: 登录表单
:return: 用户信息 + token
"""
res = UserService.login(loginForm)
return Results.success(data=res)
@route('/logout', methods=['GET', 'POST'])
def logout(self):
"""
注销 退出
:return:
"""
UserService.logout()
return Results.success(data=True)
@route('/updatepwd', methods=['POST'])
@validate(UpdatePwdForm)
def updatepwd(self, updatePwdForm):
"""
修改自己密码
:return:
"""
UserService.updatepwd(updatePwdForm.newpwd.data, updatePwdForm.oldpwd.data)
return Results.success(data=True)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Built-in Exceptions — Python 3.11.1 documentation
The built-in exception classes can be subclassed to define new exceptions; programmers are encouraged to derive new exceptions from the Exception class or...
Read more >Make a Python class throw an error when creating a new ...
Because good_attr , etc. are defined on the class the hasattr() call returns True for those attributes, and no exception is raised. You...
Read more >Python Class Constructors: Control Your Object Instantiation
Class constructors are a fundamental part of object-oriented programming in Python. They allow you to create and properly initialize objects ...
Read more >The 10 Most Common Mistakes That Python Developers Make
If a module has already been imported, Python is smart enough not to try to re-import it. However, depending on the point at...
Read more >Python Classes/Objects - W3Schools
class definitions cannot be empty, but if you for some reason have a class definition with no content, put in the pass statement...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, you will have to pass it along the whole way. If you really want something similar to Flask, you can use contextvars but they are a complicated beast and I would prefer to just pass the values around.
Thanks for the help here @retnikt ! 👏 🙇
Thanks for reporting back and closing the issue @1144388620lq 👍