附加到Pycharm中的flask过程,但是该过程正在“完成”,退出代码为0,但未执行任何操作

时间:2019-06-30 17:27:57

标签: python flask pycharm

我有一个在调试模式下运行的Flask服务器,并且正在尝试将调试器连接到它。我转到pycharm,找到该进程并尝试附加,但它只是返回。图片附上。我仔细检查了一下,PID是正确的,但实际上似乎并没有出现。

pycharm id

pycharm ide]

def my_function(request):
def hello_world(request):
    """Responds to any HTTP request.
    Args:
        request (flask.Request): HTTP request object.
    Returns:
        The response text or any set of values that can be turned into a
        Response object using
        `make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
    """
    # Set CORS headers for the preflight request
    headers = {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
        # 'Access-Control-Max-Age': '3600',
        'Access-Control-Allow-Headers': 'Content-Type'
    }

    if request.method == 'OPTIONS':
        # Allows POST requests from any origin with the Content-Type
        # header and caches preflight response for an 3600s
        return '', 200, headers

    request_json = request.get_json()
    # print("request.get_data(): ", request.get_data())
    # print("class name: ", request.get_data().__class__.__name__)
    # print("data string: ", request.get_data().decode('utf-8'))
    print("request.files: ", request.files)
    print("request.files.items(): ", request.files.items())
    print("attributes: ", request.files.__dict__)
    # for x in request.files.iteritems():
    #   print(x)

    if request.args and 'message' in request.args:
        return "OK"
        return request.args.get('message')
    elif request_json and 'message' in request_json:
        return "OK"
        return request_json['message']
    else:
        return 'Hello World!'


if __name__ == "__main__":

  from flask import Flask, request

  app = Flask(__name__)


  @app.route('/', methods = ['GET', 'POST'])
  def index():
      return my_function(request)


  app.run('127.0.0.1', 8000, debug=True)

0 个答案:

没有答案