Views & Templates Flashcards

1
Q

What are Views in Django?

A
  • Views in Django are Python functions or classes that receive web requests and return web responses.
  • Views contain the logic to process requests, retrieve data from models, and render responses.
  • Views are typically defined in the ‘views.py’ file of Django applications
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe URL Mapping

A
  • URL patterns map URLs to views in Django
  • URL patterns are defined in the ‘urls.py’ module of Django applications
  • URL patterns can include route parameters captured from the URL and passed to view functions as arguments.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are Function-Based Views?

A
  • Function-based views are Python functions that handle web requests.
  • Function-based views receive an HhttpRequest object as input & return an HttpResponse object as output.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are Class-Based Views?

A

*Class-based views are Python classes that encapsulate the logic for handling web requests.
* Class-based views offer reusable and extensible components for handling common web patterns.

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

What are Template Basics?

A

*Templates in Django are HTML files that define the structure and presentation of web pages.
* Django templates allow dynamic content using template tags and filters.
- Template tags are enclosed in {% %} and execute logic within templates.

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

How does the Render function work?

A
  • The render function takes in
  • HttpRequest Object
  • Template Name
  • Context Data
    As arguments and renders template in views.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe Template Inheritance

A
  • Template inheritance allows you to create a base template with common elements and extend it in other templates.
  • Use the {% extends %} tag to inherit from a base template and override specific blocks using the {% block %} tag.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly