Django Level Three Flashcards

1
Q

List 3 advantages of using Django’s forms functionality?

A
  1. Generate HTML form widgets quickly
  2. Quicker data validation and processing into a python data structure
  3. Create form versions of Models, models can be updated from forms.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are all the necessary tasks (5) for adding a form to your application?

A
  • Create the forms.py file
  • Create the forms; similar to models
  • Create a view for the form
  • Map the view
  • Code out the html template
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

syntax for template tagging?

A

{{ form }}

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

what does HTTP stand for?

A

Hypertext Transfer Protocol

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

What was HTTP designed for?

A

communication between a client and a server where the client submits a request and the server responds with what was requested.

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

What does a GET Request do?

A

Requests data from a resource

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

What does a POST request do?

A

submits data to be processed into a resource

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

in the template tag {{ form.as_p }} what is the .as_p for?

A

formats the form to look nicer

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

what do you need to place under your forms template tag in order for it to work?

A

{% csrf_token %}

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

what does csrf_token stand for?

A

cross site request forgery token

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

what does the csrf_token do in a nutshell?

A

verifies data

make sure it gets to where it’s going

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

How does a csrf_token work?

A

checks to see that “hidden input” code matches

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

A form class inherits from …

A

forms.Form in the same way that a model class inherits from models.Model

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

in a form class, field classes are accessed from what module?

A

the forms module

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

What arg can you add into the CharFIeld() class to format how it looks?

A

widget=forms.Textarea

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

when importing from the same directory that the current file is in, what can you use in place of the name of that file?

A

a dot.

17
Q

What is the naming convention for a forms view function?

A

form_name_view

18
Q

How do you pass a form into a view?

A

instantiate it:

19
Q

in the forms template, the form tag should have a method attribute set equal to ___

A

“POST”

20
Q

in the template, what goes inside of the form tag

A

2 template tags containing the form and the csrf token

21
Q

what must you add to the view function to have it actually do something with the forms information when submitted?

A

if request.method == ‘POST’

22
Q

inside of the if request.method == ‘POST’: block there must be …

A
  1. a new instance of the form pulled from request.POST
  2. a validation check on the form with code to run if it passes and or fails.
23
Q

How do you reference data that was passed into the form?

A

form.cleaned_data[‘name’]

this grabs whatever info got passed into the field called name in the form.

24
Q

Steps for adding a botcatcher validator to a form?

A
  1. create the field in the form class
  2. pass in 3 args
    1. required=False
    2. widget=forms.HiddenInput
    3. validators=[validators.MaxLengthValidator(0)]
25
Q

How do you make and use your own validation check?

A
  1. create a function in the forms.py file that takes in a value and checks for a certain condition and raises a validation error if things dont check out.
  2. pass that function into an attributes field class using a kwarg validators=[function_name]
26
Q

How do you create validation checks using the clean() function?

A
  1. def the clean function within the forms class
  2. instantiate super().clean() as all_clean_data (arbitrary name)
  3. instantiate the data from whichever fields usign all_clean_data[‘field’]
  4. use that data to make a validation check using logic
27
Q

Where is forms imported from?

A

django

28
Q

Where is validators imported from?

A

django.core