400 http error on all post method of a blueprint
So I have this project that I have added a blueprint to it... everything worked fine and I tested the endpoints. All good All ok .
Now after 2 weeks I'm debugging and testing the tasks I have done in the sprint and now all of my requests getting 400 HTTP Error....
Any idea what could have caused the problem ?
app file
from my_bp import bp
app.register_blueprint(bp,url_prefix="/test")
my_bp file
bp = Blueprint("my_bp",__name__)
@bp.route("/test",methods=["GET","POST"]
def test():
return {"test":"helloworld"}
Now if I send a get request via postman it's all good, but when I try to send a simple post request without a body ( or with the body ) I get the 400 Error response...
Thanks in advance
P.S. All other blueprints are doing fine but this one is returning 400 on all of my post requests P.S. I use Post-man for sending requests
So it turns out it's related to Flask-WTF CSRF protection .....
For anyone who does not know why they can't get their route running here is the answer.
app.init.py:
...
from flask_wtf.csrf import CSRFProtect
...
...
csrf = CSRFProtect()
...
and after initializing your csrf protection you need to exempt the routes :
from app import csrf
bp = Blueprint("my_bp",__name__)
@csrf.exempt
@bp.route("/test",methods=["GET","POST"]
def test():
return {"test":"helloworld"}