Skip to content

Commit

Permalink
Fix 404 page crash
Browse files Browse the repository at this point in the history
The 404 page crashes when the user is logged in:

      File "/home/zorun/code/ihatemoney/ihatemoney/templates/404.html", line 1, in top-level template code
        {% extends "layout.html" %}
      File "/home/zorun/code/ihatemoney/ihatemoney/templates/layout.html", line 124, in top-level template code
        {{ g.logout_form.hidden_tag() }}
      File "/home/zorun/venv/py3-ihatemoney/lib/python3.9/site-packages/jinja2/environment.py", line 474, in getattr
        return getattr(obj, attribute)
    jinja2.exceptions.UndefinedError: 'flask.ctx._AppCtxGlobals object' has no attribute 'logout_form'

This is because the logout form is defined by a URL processor, and this
does not seem to apply for all pages.

To solve this, simply skip the logout form if it's not defined.
  • Loading branch information
Baptiste Jonglez authored and zorun committed Jul 28, 2023
1 parent be961e9 commit ad5b108
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ihatemoney/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,14 @@ <h6 class="dropdown-header">{{ _('Languages') }}</h6>
{% if session['is_admin'] %}
<li><a class="dropdown-item" href="{{ url_for("main.dashboard") }}">{{ _("Dashboard") }}</a></li>
{% endif %}
{% if g.logout_form %}
<li>
<form action="{{ url_for("main.exit") }}" method="post">
{{ g.logout_form.hidden_tag() }}
{{ g.logout_form.submit(class="dropdown-item") }}
</form>
</li>
{% endif %}
</ul>
</li>
{% endif %}
Expand Down

0 comments on commit ad5b108

Please sign in to comment.