Python Django-the Practical Guide ✪ [ Premium ]
# Create Post.objects.create(title="Hello", content="World") posts = Post.objects.all() post = Post.objects.get(id=1) Update post.title = "New Title" post.save() Delete post.delete() 6. Django Admin Interface Create a superuser:
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware') Run: python django-the practical guide
python manage.py startapp blog Add 'blog' to INSTALLED_APPS in settings.py . blog/views.py # Create Post
python manage.py makemigrations python manage.py migrate # Create Post.objects.create(title="Hello"
CBVs reduce code repetition significantly. blog/tests.py
(create this file)
from django.http import HttpResponse from django.shortcuts import render def home(request): return HttpResponse("Welcome to my blog")