Learn Django

View Contact - Create View

The next step is to build the view to display contact details. This is a relatively simple FBV that accepts a uuid and returns a template to display the details of a contact.

Open the /.../crmeasy/crmapp/contacts/views.py file in your IDE. Delete its contents and add this code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from django.shortcuts import render
from django.contrib.auth.decorators import login_required

from .models import Contact


@login_required()
def contact_detail(request, uuid):

    contact = Contact.objects.get(uuid=uuid)

    return render(request, 
                'contacts/contact_detail.html', 
                {'contact': contact}
    )

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 "created the contact detail view"

Track your progress with a free account