【问题标题】:Flask (on apache mod_wsgi) returns BuildError烧瓶(在 apache mod_wsgi 上)返回 BuildError
【发布时间】:2013-12-16 18:40:30
【问题描述】:

我的网络服务器上的 Flask 有问题(带有 mod_wsgi 的 apache):

[Sat Nov 30 20:19:45 2013] [error] ERROR:app:Exception on / [GET]
[Sat Nov 30 20:19:45 2013] [error] Traceback (most recent call last):
.....
[Sat Nov 30 20:19:45 2013] [error] File "/usr/local/lib/python2.7/dist-packages/werkzeug/routing.py", line 1620, in build
[Sat Nov 30 20:19:45 2013] [error]     raise BuildError(endpoint, values, method)
[Sat Nov 30 20:19:45 2013] [error] BuildError: ('tool', {}, None)

在使用内置开发服务器测试应用时,一切正常。目的是,您可以在 /tool 的表单中输入数据,提交,站点重新加载并显示图像。问题是,flask/werkzeug 没有建立到 /tool 的链接。 我的路线.py:

from flask import Flask, render_template, request, send_file, make_response, url_for
from forms import SynopForm
from flask.ext.seasurf import SeaSurf

@app.route('/')
def home():
    return render_template('home.html')

@app.route('/about')
def about():
    return render_template('about.html')

@app.route('/tool', methods=['GET', 'POST'])
def tool():
    form = SynopForm(request.form)
if request.method == 'POST':
    synoptxt = str(form.name.data) 
    return render_template('tool.html', form=form, success=True)

elif request.method == 'GET':
    return render_template('tool.html', form=form)
....

我的 layout.html:

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
  </head>
  <body>
  <header>
    <div class="container">
      <img class="logo" height="70" src="{{ url_for('static', filename='img/entwurf_logo_w.png') }}" alt="logo">
      <nav>
        <ul class="menu">
          <li><a href="{{ url_for('home') }}">Home</a></li>
          <li><a href="{{ url_for('tool') }}">Tool</a></li>
          <li><a href="{{ url_for('about') }}">About</a></li>
        </ul>
      </nav>
    </div>
  </header>  
    <div class="container">
      {% block content %}
      {% endblock %}
    </div>    
  </body>
</html>

我不知道为什么它可以在我的本地电脑上运行,但在服务器上却不行。如果有人有一个很棒的解决方案。

最好的问候,马丁

【问题讨论】:

  • 服务器之前是否在运行,您添加了“构建”视图,但从未启动过服务器?它可能正在尝试呈现新模板,但由于您网站的旧实例在内存中,它不知道新的tool 视图。重新启动服务器应该会有所帮助。
  • 非常感谢。重启 apache 解决了这个问题。

标签: python apache flask mod-wsgi werkzeug


【解决方案1】:

正如在 cmets 中发现的那样,问题在于 Apache 在内存中仍有旧版本的应用程序以及旧路由。这个内存版本将尝试渲染具有新路由的新模板。重新启动 Apache 服务器会使用新路由将新版本的 Flask 应用程序加载到内存中。

【讨论】:

    猜你喜欢
    • 2020-04-02
    • 2014-05-23
    • 2014-03-03
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 2018-10-06
    • 1970-01-01
    相关资源
    最近更新 更多