知らないが、私は、エラーにAttributeError: 'NoneType' object has no attribute 'app'
私はフラスコは私が私のtests.pyファイル内のアプリをインスタンス化したいと思いますが、私は、私はフラスコは私がアプリをインスタンス化したいと思いますどのように
を取得していますする方法を知りませんトレースバック:
C:\Users\Mlamba\Envs\vir\Scripts\python.exe D:/code/web-projects/Bucketlist-Python-Flask-project/tests.py
E
======================================================================
ERROR: test_index_view (__main__.ViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:/code/web-projects/Bucketlist-Python-Flask-project/tests.py", line 11, in test_index_view
response = make_response(render_template("index.html"))
File "C:\Users\Mlamba\Envs\vir\lib\site-packages\flask\templating.py", line 132, in render_template
ctx.app.update_template_context(context)
AttributeError: 'NoneType' object has no attribute 'app'
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
Run.pyファイル:
のinitの.pyファイル:
from flask import Flask
# Load the views
from app import views
# Initialize the app
app = Flask(__name__, instance_relative_config=True)
# Load the config file
app.config.from_object('config')
テストファイル:
import unittest
from flask import render_template, make_response
class ViewTests(unittest.TestCase):
def test_index_view(self):
"""
Test that index page is accessible without login
"""
response = make_response(render_template("index.html"))
self.assertEquals(response.status_code, 200)
if __name__ == '__main__':
unittest.main()
ディレクトリ構造:
|-- README.md
|-- __pycache__
| `-- config.cpython-36.pyc
|-- app
| |-- __init__.py
| |-- __pycache__
| | |-- __init__.cpython-36.pyc
| | `-- views.cpython-36.pyc
| |-- models.py
| |-- static
| |-- templates
| | |-- index.html
| | `-- layout.html
| `-- views.py
|-- config.py
|-- requirements.txt
|-- run.py
`-- tests.py
あなたのテストでは、docstringが何を言っているか、つまりログインせずにインデックスページにアクセスできるかどうかをチェックすることは全くありません。 –
しかし、実際の問題については、完全なトレースバックを表示してください。 –
質問にトレースバックを追加しました –