question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] python class not support

See original GitHub issue

class 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
retniktcommented, Apr 29, 2020

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.

0reactions
tiangolocommented, Jun 5, 2020

Thanks for the help here @retnikt ! 👏 🙇

Thanks for reporting back and closing the issue @1144388620lq 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found