Route with authentication

    0

    0

    flask
    Python public recipes

    Create route in flask with request argument

    Library: flask

    @app.route('/')
    @app.route('/hello')
    def methodName():
        name = request.args.get('name')
        if name is None:
            name = request.cookies.get('name', 'Human')
        response = '<h1>Hello, %s!</h1>' % escape(name)  # escape name to avoid XSS
        # return different response according to the user's authentication status
        if 'logged_in' in session:
            response += '[Authenticated]'
        else:
            response += '[Not Authenticated]'
        return response
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.