Learn Django

Edit Contact - Create/Update Templates

With the edit contact resources created, we can now update the templates to activate the edit link and form action.

Update Contact Edit Link

Open contact_item_view.html, find the '{# Contact Edit Link #}' comment, and update the href attribute as follows.

1
2
3
{# Contact Edit Link #}
<a class="pen edit-contact"
   href="{{ contact.get_update_url }}?account={{ account.id }}"></a>

Update Contact Item Form

Open contact_item_form.html, locate the opening form tag, and update the action attribute:

1
2
3
4
5
<form id="contact-form"
      {# POST Destination #}
      action="{% if contact.uuid %}
      {% url 'contact_update' contact.uuid %}{% else %}{% url 'contact_new' %}{% endif %}"
      method="post">

Commit Changes

Execute these commands to commit your changes in Git.

1
2
3
4
5
# add files
(venv)$ git add .

# commit files
(venv)$ git commit -m "updated templates to allow for contact edits"

Track your progress with a free account