Здравствуйте. Есть у меня страница которая посылает аяксом запрос, когда пытаюсь получить что-то с request выдает ошибку
AttributeError: 'function' object has no attribute '...'
Мой main.py:
import logging
from flask import Flask, request
app = Flask(__name__)
@app.route('/')
def index():
"""Return a friendly HTTP greeting."""
return """
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.ajax({
url: '/request',
type: 'post',
contentType: "application/json; charset=utf-8",
data: {"test":"5"},
success: function (data) {
console.log(data);
}
});
});
</script>
"""
@app.route('/request', methods=['POST'])
def request():
return request.method # здесь выдает ошибку
@app.errorhandler(500)
def server_error(e):
logging.exception('An error occurred during a request.')
return """
An internal error occurred: <pre>{}</pre>
See logs for full stacktrace.
""".format(e), 500
if __name__ == '__main__':
# This is used when running locally. Gunicorn is used to run the
# application on Google App Engine. See entrypoint in app.yaml.
app.run(host='127.0.0.1', port=8080, debug=True)
# [END app]
Вот текст ошибки:
Traceback (most recent call last):
File "F:\Other\Python3\lib\site-packages\flask\app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "F:\Other\Python3\lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "F:\Other\Python3\lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "F:\Other\Python3\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "F:\Other\Python3\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "F:\Other\Python3\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "F:\Other\Python3\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "F:\Other\Python3\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "F:\Other\Python3\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "F:\Other\Python3\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "F:\Python projects\flask\main.py", line 45, in request
return request.method # здесь выдает ошибку
AttributeError: 'function' object has no attribute 'method'