当索引路由工作时,Flask 中的路由调用会导致 404

Routing Call in Flask leads towards 404 when index routing works

我在尝试使用 Amazon Machine Image (AMI) Apache 和 Peewee 在 Flask 中路由 URL 时遇到问题。本质上,我正在尝试使用 GET 检索数据库内容,并使用 POST 将数据插入数据库。索引路由(“/”)有效,但在那之后,/api 发送到不允许的方法,其他调用根本无法使用 /api/1 获得 404 错误和 /api/random+string/1 也收到 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>

我去修改了 wsgi 文件以确保它正确导入。我还重新启动了 httpd (apache) 以确保文件 "synced" 并且它是 运行 正确。最后,我检查了错误日志以确保我的代码正确并且似乎有效。