reading-notes

*Course 401 Python, Entry 31: Django REST Framework & Docker

What are the key components of a Docker container, and how do they help streamline the development and deployment of applications?

Describe the primary steps involved in building a library website using Django, including essential components like models, views, and templates.

  1. Create a new virtual environment, activate it, and install Django.
  2. Run the startproject line. django-admin startproject django_project .
  3. Migrate. python3 manage.py migrate
  4. Verify working with runserver. python3 manage.py runserver

  1. Create new app. python3 manage.py startapp books
  2. Add app to INSTALLED_APPS in settings.py. "books.apps.BooksConfig",
  3. Models.py. Update to as follows:
# books/models.py
from django.db import models


class Book(models.Model):
    title = models.CharField(max_length=250)
    subtitle = models.CharField(max_length=250)
    author = models.CharField(max_length=100)
    isbn = models.CharField(max_length=13)

    def __str__(self):
        return self.title
  1. Run makemigrations for the books app. python3 manage.py makemigrations books
  2. Now migrate. python3 manage.py migrate
  3. Admin. Create a superuser account. python3 manage.py createsuperuser
  4. Update books admin.py.
# books/admin.py
from django.contrib import admin

from .models import Book

admin.site.register(Book)
  1. Views. Update to as follows:
# books/views.py
from django.views.generic import ListView

from .models import Book


class BookListView(ListView):
    model = Book
    template_name = "book_list.html"
  1. URLs. Update the top-level urls to as follows:
# django_project/urls.py
from django.contrib import admin
from django.urls import path, include  # new

urlpatterns = [
    path("admin/", admin.site.urls),
    path("", include("books.urls")),  # new
]
  1. Create a urls file for the app as follows:
# books/urls.py
from django.urls import path

from .views import BookListView

urlpatterns = [
    path("", BookListView.as_view(), name="home"),
]
  1. Create a file books/templates/books/book_list.htm and edit as follows:
<!-- books/templates/books/book_list.html -->
<h1>All books</h1>

Can you explain the primary differences between Django and Django REST framework?

The major differences with Django REST are:



Things I want to know more about

How to streamline the installation of all the Django REST components.