url_for build error
- From:
- Rob Pfeifer
- Date:
- 2012-01-25 @ 17:59
I keep getting a builderror when trying to create a link that drives
url_for with a variable. Weird part is if I reload a couple times sometimes
it will work, and then it will crash again if I go back to the main page.
Wondering if it's the function definition, the template or some
combination? Any thoughts would be greatly appreciated.
Thanks,
Rob
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] mod_wsgi
(pid=30872): Exception occurred processing WSGI script '/srv/www/
myproject.com/myproject.wsgi'., referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] Traceback (most
recent call last):, referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File
"/usr/lib/python2.7/dist-packages/flask/app.py", line 1306, in __call__,
referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] return
self.wsgi_app(environ, start_response), referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File
"/usr/lib/python2.7/dist-packages/flask/app.py", line 1294, in wsgi_app,
referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] response =
self.make_response(self.handle_exception(e)), referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File
"/usr/lib/python2.7/dist-packages/flask/app.py", line 1292, in wsgi_app,
referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] response =
self.full_dispatch_request(), referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File
"/usr/lib/python2.7/dist-packages/flask/app.py", line 1062, in
full_dispatch_request, referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] rv =
self.handle_user_exception(e), referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File
"/usr/lib/python2.7/dist-packages/flask/app.py", line 1060, in
full_dispatch_request, referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] rv =
self.dispatch_request(), referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File
"/usr/lib/python2.7/dist-packages/flask/app.py", line 1047, in
dispatch_request, referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] return
self.view_functions[rule.endpoint](**req.view_args), referer:
http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File "/srv/www/
myproject.com/myproject/__init__.py", line 40, in index, referer:
http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] return
render_template('main.html', user=user, projects = projects ), referer:
http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File
"/usr/lib/python2.7/dist-packages/flask/templating.py", line 121, in
render_template, referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] context,
ctx.app), referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File
"/usr/lib/python2.7/dist-packages/flask/templating.py", line 105, in
_render, referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] rv =
template.render(context), referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File
"/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 891, in
render, referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] return
self.environment.handle_exception(exc_info, True), referer:
http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File "/srv/www/
myproject.com/myproject/templates/main.html", line 1, in top-level template
code, referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] {% extends
"layout.html" %}, referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File "/srv/www/
myproject.com/myproject/templates/layout.html", line 103, in top-level
template code, referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] {% block
body %}{% endblock %}, referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File "/srv/www/
myproject.com/myproject/templates/main.html", line 34, in block "body",
referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] <a href="{{
url_for('viewproj', proj=project.project_name) }}">, referer:
http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File
"/usr/lib/python2.7/dist-packages/flask/helpers.py", line 195, in url_for,
referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] return
ctx.url_adapter.build(endpoint, values, force_external=external), referer:
http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] File
"/usr/lib/pymodules/python2.7/werkzeug/routing.py", line 1409, in build,
referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] raise
BuildError(endpoint, values, method), referer: http://myproject.com/
[Wed Jan 25 09:47:34 2012] [error] [client 199.58.143.128] BuildError:
('viewproj', {'proj': '12th'}, None), referer: http://myproject.com/
*Function:*
@app.route('/viewproj/<proj>', methods=['GET','POST'])
def viewproj(proj):
...
Template Excerpt:
{% for project in projects %}
<li>
<a href="{{ url_for('viewproj', proj=project.project_name) }}">
{{project.project_name}}</a></li>
{% else %}
No projects
{% endfor %}
Re: [flask] url_for build error
- From:
- Armin Ronacher
- Date:
- 2012-01-25 @ 18:50
Hi,
Is the view defined in another file? If that is the case make sure to
import it at one point so that the decorators are registered.
Regards,
Armin
Re: [flask] url_for build error
- From:
- Rob Pfeifer
- Date:
- 2012-01-26 @ 00:14
Thanks Armin. All my views are in the same file at the moment, so don't
think that's the issue
On Wed, Jan 25, 2012 at 10:50 AM, Armin Ronacher <
armin.ronacher@active-4.com> wrote:
> Hi,
>
> Is the view defined in another file? If that is the case make sure to
> import it at one point so that the decorators are registered.
>
>
> Regards,
> Armin
>