Django Overview
Django is the full-stack Python framework: the ORM (the SQL the model the class), the admin (the CRUD the auto, the 1 line the register), the template (the HTML the server the render), and the auth (the login, the session, the permission the built-in). The MTV is the pattern (the Model the data, the Template the HTML, the View the logic), and the batteries-included is the pitch (the 10 week the 1 day the admin the no the code). This chapter covers what Django is (the ORM, the admin, the template, the auth), the MTV (the 3 layers), the "batteries" (the 20 built-ins), and the Notes app the running example the chapters build on.
The MVT: The 3 layers
# the MVT (the Model, the View, the Template):
# the MODEL (the data, the DB's table):
class Note(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
created = models.DateTimeField(auto_now_add=True)
# the VIEW (the logic, the request the
# response):
def note_list(request):
notes = Note.objects.all()
return render(request, "notes/list.html",
{"notes": notes})
# the TEMPLATE (the HTML, the loop, the
# the variable):
# {% for note in notes %}
# <h3>{{ note.title }}</h3>
# {% endfor %}
The MVT is the 3 layers: the Model (the data, the table the column the constraint, the QuerySet the query), the View (the logic, the request the read, the QuerySet the fetch, the response the return), and the Template (the HTML, the variable the loop, the static the no the logic). The request flows the URL to the View, the View the QuerySet the Model, the Model the DB, and the response the Template the HTML the return - the separation is the testability (the View the mock the Model, the Model the DB the no the HTTP), and the Notes app is the running example (the Note the 2 field, the list the detail the create the view).
The Batteries: The 20 built-ins
# the BATTERIES (the 20, the no-plugin):
# the ORM (the SQL the model)
# the admin (the CRUD the auto)
# the auth (the login, the session)
# the template (the render, the cache)
# the static (the file, the collect)
# the middleware (the request the hook)
# the forms (the validate, the CSRF)
# the signals (the event, the hook)
# the cache (the memory, the Redis)
# the static the media (the upload)
# the i18n (the language, the locale)
# the compression (the gzip)
# the security (the XSS, the CSRF,
# the SQL the inject)
# the testing (the test client)
# the email (the SMTP, the 12factor)
# the logging (the log, the 12factor)
# the sessions (the cookie, the signed)
# the files (the upload, the storage)
# the pagination (the page, the 12factor)
# the syndication (the feed, the 12factor)
The "batteries-included" is the 20 built-in: the ORM (the SQL the model the no the write), the admin (the CRUD the auto, the register the 1 line), the auth (the login the user the group the permission), the template (the render the cache the extend), the static (the collectstatic the nginx), and the forms (the validate the CSRF the error the render). The security is the built-in (the XSS the template the escape, the CSRF the token the form, the SQL the inject the parameterize, the clickjacking the frame-ancestors), and the 12-factor is the setting (the env the secret, the port the 12factor, the log the stdout). The rule is the one: the ORM the data, the admin the CRUD, the auth the user, the template the HTML - the next chapter's install is the venv the pip the startproject, and the Notes app the startapp the 1 command.
The Working Rules
- The MVT is the 3 layers, the separation the test. The Model the data (the table, the QuerySet), the View the logic (the request, the fetch), and the Template the HTML (the loop, the no logic) - the View the mock the Model, the Model the no the HTTP, and the Notes app the 2 field the list the detail the create.
- The ORM is the SQL, the model the class. The field the column (the CharField, the TextField, the DateTimeField), the QuerySet the query (the all, the filter, the get), and the migration the schema (the no the SQL the write) - the 10 week the 1 day the admin the no the code.
- The admin is the CRUD, the register the 1 line. The
admin.site.register(Note)the 1 line, and the /admin the list the change the delete (the auth the require, the permission the check) - the no the view the template the form the write. - The batteries are the 20, the security the built-in. The auth, the session, the template cache, the static collect, the forms CSRF, and the i18n - the XSS the escape, the CSRF the token, the SQL the parameterize, the clickjacking the frame-ancestors (the no the plugin the add).
Summary
Django is the full-stack Python framework: the ORM (the SQL the model the no the write), the admin (the CRUD the auto, the register the 1 line), the template (the HTML the render the escape the XSS), and the auth (the login the session the permission the built-in). The MVT is the pattern (the Model the data, the View the logic, the Template the HTML), and the separation is the testability (the View the mock, the Model the no the HTTP). The "batteries-included" is the 20 built-in (the security the XSS the CSRF the SQL the inject, the i18n the 12factor the setting), and the Notes app is the running example (the Note the 2 field, the list the detail the create the view). The next chapter installs the environment: the venv, the pip the 5.x, the startproject, and the Notes app the startapp the 1 command the 2 file the no the template.