Django Level Five Flashcards

1
Q

which password hashers did we install?

A

argon2: pip install django[argon2]
bcrypt: pip install bcrypt

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

to use a password hasher, it must be added to the ____ in settings.py

A

PASSWORDS_HASHERS list

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

syntax for adding an option to a password validator

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

What is the difference between static files and media files?

A

content that you provide (static) versus content that your user provides (media)

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

code for setting up static and media directories.

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

what library must be installed in order to work with images?

A

the python imaging library:

pip install pillow

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

always remember to register models that you want admin control over to the ___

A

admin.py file

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

Broad steps for creating a UserProfileInfo() model

A
  1. import models and User
  2. define the class
  3. instatiate the user field which uses the imported User model as its base by way of the .OneToOneField() method
  4. add additional fields to the UserProfileInfo model
  5. def a string representation of the model
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what does the on_delete=models.cascade mean as an argument in a OneToOneField() or ForeignKey()?

A

When the referenced model is deleted, also delete other model instances that referenced it.

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

what does the blank=true mean as an argument in a FieldClass?

A

Information for that field can remain blank

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

When using an ImageField() class, how does it know where the file should be stored?

A

add the kwarg: upload_to=’profile_pics’

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

List the broad steps for creating a Form class in forms.py

A

1. import forms, User, and UserProfileInfo from their respective sources

  1. define the class
  2. add any fields that are not already present in the model that we are creating a form for (this step can be skipped).
  3. define a class Meta() with model equal to the mode we are basing the form off of, and the fields from that model (and the form class) that we want to add to the form.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is the code for adding a password input widget to a Form class?

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

what are the heirarchy of tags when creating a navbar?

A
  • nav
    • div
      • ul
        • li
        • li
        • li
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

how do you change how each button in a navbar looks?

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

List the broad steps for creating a registration form in an html file (dont worry about styling).

A
  1. check if the user is registered
  2. If the user is not registered display the form using template tags and the csrf_token
  3. add a submit button
17
Q

it may be good practice to place a form inside of what kind of div class value?

A

jumbotron

18
Q

for the form tag, what should the two attributes be, what are they equal to, and what is their purpose?

A

enctype=”multipart/form-data”

  • needed since we are uploading multimedia images

method=”POST”

  • tells Django that submission of this form yields a post request.
19
Q

List the broad steps for creating the register view function.

A
  1. import render from django.shortcuts and import the UserProfileInfoForm
  2. initialize the registered value to equal false
  3. with an if statement give instructions for the request being a “POST” which is to pull (instantiate) the data entered into the forms. if not a “POST” request, we will get back the empty forms.
  4. with a nest if statement check for validation of the instantiated forms. will print error reports if validation fails.
  5. save all the data entered into the form using the appropriate statements and flip registered to equal True
  6. return a render with the dictionary containing all the variables needed for the html file.
20
Q

what does request.method == “POST” mean?

A
  • The user submitted a form that they filled
  • No we need to do something with the provided information
21
Q

what method checks for the validity of a form?

A

.is_valid()

22
Q

how do we hash and save the user password?

A

user.password ultimately comes from the password that we entered into the form.

23
Q

why would we ever pass the kwarg commit=False into a save() method?

A

If we want to hold off on saving in the case that contradictions arise.

24
Q

what is this line of code doing?

profile.user = user

A

it is establishing that OneToOne relationship referenced earlier in models.py

25
Q

What is this block of code saying?

A

if a profile_pic was submitted with the request,

set the profile_pic attribute of the profile to equal whatever was submitted.

26
Q

How do you estalbish a login url?

A

in settings.py,

27
Q

What are the crucial components of a login html file?

A
  • form tag(s)
  • csrf_token
  • label and input tags for the Username, and Password entry with ‘for’ and ‘name’ matching.
    • type=’text’ for Username
    • type=’password’ for Password
  • an input tag for the submit button
28
Q

list the sequential operations done in the user_login view function.

A
  • if “POST”
    • instantiate username and password using POST.get(‘ ‘)
    • authenticate the user
    • if there is a user
      • if the user is active
        • log them in and take them back to the index
      • else user not active
        • report that the account is not active
    • else (no user)
      • print an invaled login details report
  • else (no “POST”)
    • render the page normally
29
Q

for the login view:

how do you instantiate username and password using POST.get(‘ ‘)

A
30
Q

In the login view:

How do you authenticate a user?

A
31
Q

In the user_login view how do you:

log the user in and return them to the index page?

A

62-64

32
Q

In the user_login view how do you:

report that the account is not active?

A

66-67

33
Q

In the user_login view how do you:

print login failure messages to the console and to be displayed in the browser.

A

69-72

34
Q

describe the logout view

A
  • login required decorator
  • logout function with request arg
  • return statement that takes the user back to the index page
35
Q

code for adding a navbar link for longing in or logging out?

A
  • if user is authenticated
    • the last navbar item is a logout link
  • else (user not authenticate)
    • the last navbar item is a login link