Learn Django

Update Base & Home Templates

The home page contains two links to the signup form. Now that the form is built you can update the links to point to it.

Update the Base Template

First, open /.../crmeasy/crmapp/templates/base.html and update this HTML.

1
2
3
4
5
# old code
<li><a href="" class="p-r-none">Sign Up</a></li>

# new code
<li><a href="{% url 'sub_new' %}" class="p-r-none">Sign Up</a></li>

Update the Home Template

There are also two links on the home page that connect to the signup page. Open /.../crmeasy/crmapp/templates/marketing/home.html for editing. Locate the two links below and update the href= attribute on both.

1
2
3
4
5
6
7
8
9
{# First Signup Link #}
<a href="{% url 'sub_new' %}"
   class="sign-up btn btn-success">Sign Up Now for $15/month!
</a>

...

{# Second Signup Link #}
<a href="{% url 'sub_new' %}" class=" sgn-btm ">SIGN UP FOR ONLY $15/MONTH</a>

Code Review

Line 2 & 9: This is the first time the {% url %} tag is used. This tag takes a URL name as a parameter and renders it's path. In the previous lesson you created the /signup/ URL and named it 'sub_new'. This tag is able to render the right path just given the name. This is extremely useful if you consider a scenario where we have numerous marketing pages all pointing to the signup form. If we use the {% url %} tag all we have to do is update the URL in the urls.py file instead of updating every marketing page.

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 base and home templates with signup link"

Track your progress with a free account