Я пытаюсь проверить контекст root локального приложения http://127.0.0.1:5000/
с ответом JSON вместо обычного render_template
.
У меня есть portfolio.py:
from flask import Flask, json
app = Flask(__name__)
@app.route("/")
def home():
response = app.response_class(
response=json.dumps("message": "Application homepage"),
status=200,
mimetype='application/json'
)
return response
И когда я делаю:
curl -X GET -v 'http://127.0.0.1:5000/
Я всегда вижу:
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:5000
> User-Agent: curl/7.64.1
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 404 NOT FOUND
< Content-Type: text/html; charset=utf-8
< Content-Length: 232
< Server: Werkzeug/1.0.0 Python/3.7.6
< Date: Mon, 30 Mar 2020 17:22:07 GMT
<
<!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>
* Closing connection 0
Как вместо этого получить пользовательский ответ JSON от def home()
из перечисленного?