I'm trying to send a POST request to a PHP script from Flask. I am using a Datatables Editor to get information from a backend database. Datatables will send a POST request to get the data it needs when DOM is ready. However, I'm getting the following error:
Method Not Allowed The method is not allowed for the requested URL.
Here's the route:
@bp.route('/my_php', methods=['GET', 'POST'])
def php_post():
url = 'http://localhost:5000/static/datatables-plugins/Editor-PHP-1.7.4/examples/php/staff.php'
headers = {
'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding': 'gzip, deflate, br',
'X-Requested-With': 'XMLHttpRequest'
}
data = urllib.parse.urlencode(request.form).encode('utf-8')
resp = requests.post(url, data=data, headers=headers)
return json.dumps(resp.content).encode('utf-8')
I think this may have to do with specifying allowed methods, however I don't know how to explicitly allow for GET/POST methods when a request for another URL is called within the Flask route.
</div>