I'm having trouble trying to route URLs in Flask using an Amazon Machine Image (AMI) Apache, and Peewee. Essentially, I'm trying to use a GET to retrieve database content and a POST to insert data into the database. Index routing ("/") works but after that, /api sends to a Method Not allowed and other calls simply do not work with /api/1 getting a 404 error and /api/random+string/1 also getting a 404.
#!/usr/bin/env python
import re, os, sys, time, shutil, numpy, cgi, cgitb, json, peewee, playhouse
from peewee import *
from flask import *
cgitb.enable()
mainapp = Flask(__name__)
###Some code here
@mainapp.route("/api/<int:task_id>", methods=['GET'])
def get_task(task_id):
try:
j = R.get(R.rid ==task_id)
except R.DoesNotExist:
print "aborting because it doens't exist"
abort(400)
##3Take data into Json ready format
db.close()
return jsonify(##Json format)
@mainapp.route('/')
curl -i website/api/1
HTTP/1.1 404 NOT FOUND
Date: Wed, 26 Oct 2016 19:52:53 GMT
Server: Apache/2.4.23 (Amazon) PHP/5.6.26 mod_wsgi/3.5 Python/2.7.12
Content-Length: 233
Content-Type: text/html; charset=UTF-8
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>