7.1. Views About

7.1.1. Responses

  • HttpResponse

  • JsonResponse

7.1.2. Assignments

# FIXME: Write tests

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: Django View About
# - Difficulty: easy
# - Lines: 3
# - Minutes: 3

# %% English
# 0. Use `myproject.shop`
# 1. Create function based view `index_view()`
# 2. Create `shop/index.html` template with content: `Hello World!`
# 3. Use `django.shortcuts.render` to render template
# 4. Register view in `urls.py` with name `shop-index-fbv`

# %% Polish
# 0. Użyj `myproject.shop`
# 1. Stwórz widok oparty o funkcję `index_view()`
# 2. Stwórz szablon `shop/index.html` z treścią: `Hello World!`
# 3. Użyj `django.shortcuts.render` do renderowania szablonu
# 4. Zarejestruj widok w `urls.py` z nazwą `shop-index-fbv`

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
"""

# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()

...

# FIXME: Write tests

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% About
# - Name: Django View About
# - Difficulty: easy
# - Lines: 3
# - Minutes: 3

# %% English
# 0. Use `myproject.shop`
# 1. Create class based view `IndexView`
# 2. Create `shop/index.html` template with content: `Hello World!`
# 3. Use `django.views.generic.TemplateView` to render template
# 4. Register view in `urls.py` with name `shop-index-cbv`

# %% Polish
# 0. Użyj `myproject.shop`
# 1. Stwórz widok oparty o klasę `IndexView`
# 2. Stwórz szablon `shop/index.html` z treścią: `Hello World!`
# 3. Użyj `django.views.generic.TemplateView` do renderowania szablonu
# 4. Zarejestruj widok w `urls.py` z nazwą `shop-index-cbv`

# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 10), \
'Python 3.10+ required'
"""

# Required for Django to work
import os; os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django; django.setup()

...