I would like to redirect to a route that allows multiple methods.
When using the following, redirect happens as a GET
request. However the route message
accepts POST
request also other than the default GET
request.
contactform_schema = { 'fullname': {'type': 'string', 'maxlength': 80, 'required': True}, 'email': { 'type': 'string', 'regex': emailregx, 'required': True }, 'phone': {'type': 'string', 'maxlength': 18, 'required': True}, 'message': {'type': 'string', 'maxlength': 1200, 'required': True}, 'vehicle_count': {'type': 'number', 'min':0, 'max':1000000, 'required': True} } @app.route("/contactform", methods=['POST','OPTIONS']) @validate_json(contactform_schema) def pocontactformst(request): phone = request.json.get('phone', None) if phone_check(phone) == True : return response.redirect('/message',content_type='application/json') else: return json({'status': 'PhoneNumberFormat.E164:false'}, 403)
Might be a trivial question given I just started recently with Sanic
As a background I was trying to use the sanic_crud from the listed Sanic extensions. In the above code I am just adding an extra layer of validation before redirecting the POST
request to the route message
created by sanic_crud
library. On that message
route one can create a messages in the database via a POST
request with a JSON payload.
app = Sanic(__name__) generate_crud(app, [ message]) app.run(host="0.0.0.0", port=8000, debug=True)