Django Level One Flashcards

1
Q

What 2 major problems can we solve with Django?

A
  1. Map a requested URL from a user, to the code written to handle it.
  2. Create a requested HTML page dynamically using templates that transfer back-end information to the front end.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why use a venv?

A

It’s like creating a unique workspace where all things added to it are used for the project, and nothing outside of it is.

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

Cmd for creating a venv? what if you want to specify a certain version of python?

A

conda create –name nameOfEnv django

conda create –name nameOfEnv python=3.5

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

What command returns a list of all the envs installed on your computer?

A

conda in –envs

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

Commands to activate and deactivate a venv?

A

conda activate nameOfEnv

conda deactivate nameOfEnv

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

command for installing django into a venv?

A

conda install django

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

For the command line statements that start with conda, what would they start with if i was not using the conda distribution of python?

A

pip

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

What is the command line statement for starting a new django project?

A

django-admin startproject name_of_project

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

Command for running the server.

A

python manage.py runserver

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

What are migrations?

A

an automized process of updating database structures, usually done after making changes to an applications models.py file.

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

Define a Django Project in your own words?

A

The apps and configurations that make up a purposeful functioning website.

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

What is a django application in your own words?

A

A part of your django project with a specific functionality, ex: workout maker app, workout viewer app, etc..

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

Command for creating a new app:

A

python manage.py startapp name_of_app

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

After creating an App using the command, what must the app be added to?

A

The installed apps list in settings.py

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

Each view for the application is represented by …

A

its own function within the views.py file that takes in request as an argument.

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

list the three arguments in order for the path function used in the urls.py file.

A
  1. The url of the app/page
  2. The associated view function
  3. the name of the associated html file
17
Q

What does the path() function look like when one is trying to connect url patterns from an app to the urlpatterns of the project?

A
  • arg1: the base url for the app
  • arg2: the include() function with the location of the urls.py file for the app as a string. ex: (first_app.urls)
  • line 22
18
Q

What are the steps for creating a template directory object in settings.py?

A
  1. Make sure that os is imported
  2. Create the template directory object using os.path.join(BASE_DIR, ‘templates’)
19
Q

What do we do with the TEMPLATE_DIR object once it is created?

A

Pass it into the dictionary contained in the TEMPLATES object in settings.py. should be passed as the value to the ‘DIRS’ key in the form of a list with the first and only item being TEMPLATE_DIR.

20
Q

What goes inside of the template folder?

A

folders named after the apps of the project to hold the template files for each app.

21
Q

What template tag connects data from a view to an HTML page?

A

{{ insert_context_key }}

22
Q

What are the 3 args passed into the render() function?

A
  1. The request
  2. A string representing the location of the html file being rendered
  3. a dictionary of key-value pairs to be used by the html page.
    1. This can be a ‘context=’ kwarg or you can straight up pass a dictionary as the last arg.
23
Q

Summarize the 6 step process for creating a new page?

A
  1. create the html file in the appropriate folder
  2. create the template directory object and place it into the right data structure in settings.py
  3. map out the urlpatterns
  4. make sure the apps urlpatterns are referenced in the projects url patterns
  5. create the view
  6. write the html template code
24
Q

What is the heirarchy of the static directory?

A

first_level_project_folder > static > images

25
Q

How do you add the static directory to the project settings.py file?

A

same we did it for the templates directory

26
Q

do you have to create your own STATICFILES_DIRS list object in the settings.py file?

A

Yes

27
Q

What code must be added to the top (under HTML doctype) to allow content from the static directory to be viewable?

A

{% load static %}

28
Q

how do you call static files into your HTML document?

A
29
Q

What is the benefit of the static files directory?

A

better organization for static files

30
Q

How should you add css files to your static files directory?

A

static > css > mystyle.css

31
Q

How do you call css files from the static directory?

A

the same way you would for an image, except you would reference the css folder not the image folder.