【问题标题】:Routing Call in Flask leads towards 404 when index routing works当索引路由工作时,Flask 中的路由调用会导致 404
【发布时间】:2016-10-26 17:36:27
【问题描述】:

我在尝试使用 Amazon 系统映像 (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>

【问题讨论】:

    标签: python apache flask peewee amazon-ami


    【解决方案1】:

    我去修改了 wsgi 文件以确保它可以正确导入。我还去重新启动 httpd (apache) 以确保文件“同步”并且它运行正常。最后,我检查了错误日志,以确保我的代码正确并且似乎可以正常工作。

    【讨论】:

      猜你喜欢
      • 2014-09-29
      • 1970-01-01
      • 2015-04-07
      • 2014-07-12
      • 1970-01-01
      • 2022-11-06
      • 2015-08-13
      • 1970-01-01
      • 2022-10-24
      相关资源
      最近更新 更多