Django Level Four Flashcards

1
Q

what is the syntax for the best method of injecting a url template into an html file?

what is required in the urls.py file that wasn’t before?

A

”{% url “basic_app:other” %}”

app_name = name_of_app should be in the apps urls.py file before the mapped url patterns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you use url template tagging to link to the admin site?

A

set the href equal to:

”{% url “admin:index” %}”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is the syntax for linking a url coming straight from the projects urls.py file?

A

”{% url “index” %}”

it is this simple since we do not need to identify an app.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

syntax for both the base.html and the html file that inherits from it.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

it is good practice to place the block template tags of the base.html inside of a …

A

div tag with class=”container”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

the second line of any html file that extends another needs to contain what?

A

a template tag that identifies the file being extended.

{% extends “basic_app/base.html” %}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

To use custom filters in an html file, one must add this to the top of the html file.

A

{% load name_of_filters_file %}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the general form for a template filter?

A

{{ value | filter: “arg” }}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What should you do before trying to build your own template filter?

A

See if django already has one built in.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

3 steps to creating a custom filters file.

A
  1. create a directory called template tags on the same level as models.py
  2. create a file called __init__.py so that python treats the directory as a module
  3. create a file inside the directory that can be called anything. this file will contain related filter tags
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What must be imported into the template filters file? what class do we instantiate from it? and for what purpose?

A

from django import template

register = template.Library()

To use as a decorator to register the function into a filter tag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

when registering a new filter tag, what arg do we pass into the decorator above the function?

A

@register.filter(name=’cut’)

the name should be the same as the functions name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What should be the first thing found in a function after the definition?

A

a docstring explaining what it does and concisely as possible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly