This question could be a simple question.
I have two python decorators having functions inside them as follows:
@app.route('/insertsql', methods=['GET', 'POST'])
@app.route('/login', methods=['GET', 'POST'])
Bad Request The browser (or proxy) sent a request that this server
could not understand.
There are a few different ways to approach this. If you want to ensure the user is logged in before running that action you could use a decorator.
@auth.login_required def before_request():
However, it could be you are really just trying to do two things within one route. How I like to handle this is by breaking up Flask apps into different components. Routes, Controllers and Models. This way a route can call multiple controller actions, where that logic isn't tightly coupled to your route and can be easily re-used.
│ └── cases.py
│ └── case.py
│ └── v1
│ ├── api_cases.py
│ └── api_test.py
Called from routes. Glue in application that are responsible for processing requests. Works by getting data in the
Models using business logic from the
Services and return results for the view. Should validate user input.
Controller Actions: Reference Guide
Database interaction related code here. Responsible for data integrity.
Handles URI requests, these are BluePrints in Flask. Calls
Controllers. Organized into a namespaced version for the api using
v1. API related routes go within this directory.