Flask配置错误

时间:2018-03-12 14:21:25

标签: python flask

我遇到烧瓶工作的问题。我是个菜鸟,还在学习Linux。运行后我得到了这个(非常令人生畏的)错误:

flask run

root@DESKTOP-TV7O885:/mnt/c/Projects/app_1# flask run
 * Serving Flask app "application"
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2018-03-12 14:10:00,550] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/mnt/c/Projects/app_1/application.py", line 7, in index
    return render_template("index.html")
  File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 133, in render_template
    return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 869, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 57, in get_source
    return self._get_source_fast(environment, template)
  File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 85, in _get_source_fast
    raise TemplateNotFound(template)
TemplateNotFound: index.html
127.0.0.1 - - [12/Mar/2018 14:10:00] "GET / HTTP/1.1" 500 -

然后页面掉线

 Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

我在VSCODE上也遇到了一个pylint错误:

 E0401:Unable to import 'flask'

我理解它可能是一个相对简单的错误,因为配置错误或安装错误。我一直试图弄清楚这一点,但我的知识存在很多差距。

我在Windows上使用Ubuntu上的Bash,我认为这就是我遇到问题的原因。如果有人能帮助我,或至少指出我正确的方向,我将非常感激

1 个答案:

答案 0 :(得分:0)

在异常的调用堆栈中,您必须从下到上,直到在项目中找到文件。这是起点。在你的情况下,它是:

File "/mnt/c/Projects/app_1/application.py", line 7, in index
  return render_template("index.html")

你说你有一个名为index.html的模板,但是(作为异常错误),Flask无法找到它。检查您是否在正确的位置具有此模板,并正确定义(当您调用Flask构造函数时)模板目录的位置。

相关问题