diff --git a/app/main/routes.py b/app/main/routes.py index 6d1e7df..1431089 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -143,7 +143,10 @@ def agent_edit(agent_id=None): # Or submit for db writing # elif request.method == 'POST': - agent_id = request.form['agent_id'] + try: + agent_id = request.form['agent_id'] + except KeyError: + agent_id = None if agent_id: # then update existing this_agent = Agent.query.get(int(agent_id)) diff --git a/app/main/templates/agent_form.html b/app/main/templates/agent_form.html index c4121b3..315b618 100644 --- a/app/main/templates/agent_form.html +++ b/app/main/templates/agent_form.html @@ -1,7 +1,7 @@ {% extends "base_page.html" %} {# Set the title that will be used in base_page #} -{% if agent['agent_id'] != '' %} +{% if agent and agent['id'] not in ['', None] %} {% set subtitle = "Modifier l'agent "+ agent['fullname'] %} {% else %} {% set subtitle = "Ajouter un nouvel agent" %} @@ -13,8 +13,8 @@