Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to properly document python flask route

i was trying to document this function and was wondering what kind of things I should include in the docstring. I am using sphinx as a documentation generator.

@app.route('/login', methods=['GET','POST'])
def login():
    """ 
    This is the Login route endpoint.

    Parameters:
        GET:/login

        POST:/login

    Returns:
        It renders the home.html template

    """
    form = LoginForm()

    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            if check_password_hash(user.password_hash, form.password.data):
                login_user(user, remember=form.remember.data)
                return redirect('/dashboard')

        return '<h1> Invalid Username or Password!. Please try again.</h1>'


    return render_template('login.html', form = form)
like image 279
e.T55 Avatar asked Nov 20 '25 10:11

e.T55


1 Answers

I would suggest you use apispec, it has support for the OpenAPI Specification. There is also a Flask plugin and generates YAML for you.

like image 123
Srikanth Chekuri Avatar answered Nov 22 '25 01:11

Srikanth Chekuri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!