## Django 101 [Mirek Biňas](https://bletvaska.github.io) / [**Namakaný webinár**](http://www.namakanyden.sk/)
[![Django](images/logo-django.png)](https://www.djangoproject.com/)
![Django](images/django-the.movie.jpg)
[![Django Reinhardt](images/django.reinhardt.jpg)](https://en.wikipedia.org/wiki/Django_Reinhardt)
> "**Django** is a high-level **Python Web framework** that encourages **rapid development** and **clean**, **pragmatic design**." > ([www.djangoproject.com](https://www.djangoproject.com))
## History of Django * internal project of newspaper [Lawrence Journal-World](http://www2.ljworld.com/) (Kansas) in 2003 * lead developer was former journalist * released as open source in 2005 (BSD licence) * in 2008 version 1.0 released * from version 1.5 in 2013 Django supports Python3
## Django Principles * DRY * write less code: > "Django is web framework for perfectionists with deadlines." * make CRUD easy * DB neutral * deployment neutral (WSGI/ASGI/CGI/...)
[![Two Scoops of Django - cover](images/cover-two.scoops.of.django.jpg)](https://www.feldroy.com/books/two-scoops-of-django-3-x)
## Recommended Project Structure ``` repository_root/ ├── configuration_root/ └─── django_project_root/ ```
## The Golden Rule of Django App Design > The art of creating and maintaining a good Django app is that it should follow the truncated Unix philosophy according to Douglas McIlroy: **"Write programs that do one thing and do it well."** (James Bennett, a Django core developer)
![](https://i.ytimg.com/vi/KskV5dWq7Tk/maxresdefault.jpg)
## FBV vs CBV
## Guidelines for Writing FBV * Less view code is better. * Never repeat code in views. * Views should handle presentation logic. Try to keep business logic in models when possible, or in forms if you must. * Keep your views simple. * Use them to write custom 403, 404, and 500 error handlers. * Complex nested-if blocks are to be avoided. notes: * two scoops of django, 9th chapter
## Template Components * **variables** - hold data ``` {{ person.name }} ``` * **tags** - perform logic ``` {% include "detail.html" %} ``` * **filters** - operate on data ``` {{ person.name | upper }} ```
![Example](https://files.speakerdeck.com/presentations/5431f020a5cf0130d06036e1e4c67336/slide_15.jpg)
[![Django REST Framework](https://www.django-rest-framework.org/img/logo.png)](https://www.django-rest-framework.org/)
[![Pytest](images/logo-pytest.webp)](https://pytest.org)
## How to Write Unit Tests
## Each Test Method Tests One Thing