所有Flask端点均返回404(未找到)

时间:2019-01-17 17:57:12

标签: python python-3.x flask

我有一个包含12个端点的API,这些API正常运行,然后端点开始出现故障,现在都返回404状态代码。这是我的一些文件 我的 run.py

import os

from app import create_app

config = os.getenv('APP_SETTINGS')
app = create_app(config)

if __name__ == "__main__":
    app.run(debug=True)

我像这样在 app.py 中注册端点

 from flask import Flask
 from .api.v2.views.userview import auth


 def create_app(config):
 '''Creates all Flask configurations and returns app.
    Expects config name'''
     app = Flask(__name__, instance_relative_config=True)
     app.config['JSON_SORT_KEYS'] = False
     app.config.from_object(app_config[config])
     app.config.from_pyfile('config.py', silent=True)

     app.url_map.strict_slashes = False
     app.register_blueprint(auth)
     return app

最后是我的端点 user.py

     from flask import request, jsonify
     from flask import Blueprint

     from ..models.usermodel import UserModel

     usr_obj = UserModel()
     auth = Blueprint('auth', __name__, '/api/v2')


     @auth.route('/auth/signup', methods=['POST'])
     def user_signup():
         fullname = request.json['fullname']
         username = request.json['username']
         email = request.json['email']
         password = request.json['password']

         data = usr_obj.inituser(fullname, username, email, password)
         return jsonify(data), 201

当我尝试运行此端点或版本1(/ api / v1)中的任何其他端点时,出现未找到错误。我也尝试过THIS SOLUTION,但没有成功。

enter image description here

1 个答案:

答案 0 :(得分:0)

我犯了一个愚蠢的错误,蓝图声明应该是

class Render extends React.Component {
  render() {
    const {
      selected: { type, view: selectedView },
      hovered: { view: hoveredView },
      getRender,
      isFirstStep,
      renders,
    } = this.props;

    const imagesPath = `/images/${isFirstStep ? 'common' : type}`;
    const rendersPath = `${imagesPath}/renders`;

    let renderComponent = null;

    const view = hoveredView || selectedView;

    if (view === 'frontal') {
      const { render } = getRender('frontal');
      renderComponent = (
        <FullPieceWrapper>
          <img src={`${rendersPath}/frontal/${render}.png`} alt="Render" />
        </FullPieceWrapper>
      );
    } else if (renders.length > 1) {
      renderComponent = (
        <PiecesWrapper>
          {renders.map((key) => {
            const { isDefault, isHidden, render } = getRender(key);
            return (
              render ? (
                <Piece
                  key={key}
                  isDefault={isDefault}
                  isHidden={isHidden}
                  src={`${rendersPath}/${key}/${render}.png`}
                />
              ) : null
            );
          })}
        </PiecesWrapper>
      );
    } else if (renders.length === 1) {
      const [key] = renders;
      const { isDefault, render } = getRender(key);
      log.setLevel('debug');
      log.debug('render is ', render);
      renderComponent = (
        <FullPieceWrapper isDefault={isDefault}>
          <img src={`${rendersPath}/${key}/${render}.png`} alt="Render" />
        </FullPieceWrapper>
      );
    } else {
      renderComponent = null;
    }

    return <Wrapper>{renderComponent}</Wrapper>;
  }
}