Question

I have a problem with Flask on my web-server (apache with mod_wsgi):

[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)

While testing the app with the build-in development server everything worked fine. The intention is, that you can enter data in the form at /tool, submit, the site reloads and a image is displayed. The problem is, that flask/werkzeug doesn't build the link to /tool. My routes.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)
....

My 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>

I don't have any idea why it works at my local pc, but not at the server. If anyone has an solution that would be great.

Best Regards, Martin

Était-ce utile?

La solution

As discovered in the comments, the issue was that Apache still had an older version of the application in memory with the old routes. This in-memory version would try to render the new templates, which had new routes. Restarting the Apache server loaded the new version of the Flask application into memory with the new routes.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top