助けてください
解決したいこと
FLASKでアプリ作成をやっている最中なのですがこのエラーが出てしまいますどうすればいいでしょうか
発生している問題・エラー
(venv) PS C:\Users\tsuch\flaskbook\apps\minimalapp> flask routes
* Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
app
connection
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\tsuch\flaskbook\venv\Scripts\flask.exe\__main__.py", line 7, in <module>
File "C:\Users\tsuch\flaskbook\venv\Lib\site-packages\flask\cli.py", line 1047, in main
cli.main()
File "C:\Users\tsuch\flaskbook\venv\Lib\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "C:\Users\tsuch\flaskbook\venv\Lib\site-packages\click\core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tsuch\flaskbook\venv\Lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tsuch\flaskbook\venv\Lib\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tsuch\flaskbook\venv\Lib\site-packages\click\decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tsuch\flaskbook\venv\Lib\site-packages\flask\cli.py", line 354, in decorator
app = __ctx.ensure_object(ScriptInfo).load_app()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tsuch\flaskbook\venv\Lib\site-packages\flask\cli.py", line 308, in load_app
app = locate_app(import_name, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\tsuch\flaskbook\venv\Lib\site-packages\flask\cli.py", line 218, in locate_app
__import__(module_name)
File "C:\Users\tsuch\flaskbook\apps\minimalapp\app.py", line 31, in <module>
with app.test_reqest_context("/users?update=ture"):
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Flask' object has no attribute 'test_reqest_context'. Did you mean: 'test_request_context'?
該当するソースコード
# Flaskクラスをインポート
from flask import Flask, current_app, g, redirect, render_template, request, url_for
# Flaskクラスをインスタンス化
app = Flask(__name__)
# URLと実行する関数をマッピング
@app.route("/")
def index():
return "Hello,Flaskbook!"
@app.route("/hello/<name>", methods=["GET", "POST"], endpoint="hello-endpoint")
def hello(name):
return f"Hello, {name}!"
@app.route("/name/<name>")
def show_name(name):
return render_template("index.html", name=name)
with app.test_request_context():
# /
print(url_for("index"))
# /hello/world
print(url_for("hello-endpoint", name="world"))
# /name/Rikuo?page=1
print(url_for("show_name", name="Rikuo", page="1"))
ctx = app.app_context()
ctx.push()
print(current_app.name)
g.connection = "connection"
print(g.connection)
with app.test_reqest_context("/users?update=ture"):
print(request.args.get("updated"))
@app.route("/contact")
def contact():
return render_template("contact.html")
@app.route("/contact/complete", methods=["GET", "POST"])
def contact_complete():
if request.method == "POST":
return redirect(url_for("contact_complete"))
return render_template("contact_complete.html")
自分で試したこと
まったくわからないので何もしていません
0