Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
What You Should Know About The Django User Model
The goal of this article is to discuss the caveats of the default Django user model implementation and also to give you some advice on how to address them. It is important to know the limitations of the current implementation so to avoid the most common pitfalls. Something to keep in mind is that the Django user model is heavily based on its initial implementation that is at least 16 years old. Because user and authentication is a core part of the majority of the web applications using Django, most of its quirks persisted on the subsequent releases so to maintain backward compatibility. The good news is that Django offers many ways to override and customize its default implementation so to fit your application needs. But some of those changes must be done right at the beginning of the project, otherwise it would be too much of a hassle to change the database structure after your application is in production. Below, the topics that we are going to cover in this article: User Model Limitations The username field is case-sensitive The username field validates against unicode letters The email field is not unique The email field is not mandatory A … -
Probably Are Gonna Need It: Application Security Edition
My list of “Probably Are Going To Need It” security features for your web app – things that you should build up-front, not wait until you need them (when it’s already too late). -
Django 3.2 Update for “Speed Up Your Django Tests” Released
I released my book “Speed Up Your Django Tests” over a year ago, in May 2020. Since then, we’ve seen two major Django releases, including a whole bunch of test-related changes, some of which I worked on as part of the book. Today I’m releasing the first update for SUYDT. The update brings the existing content up to date with Python 3.9, Django 3.2, and some future changes for Django 4.0. It also includes some new sections on mocking time and parallelizing tests. And for those who with e-readers, it now comes as an ePub file, alongside the original flavour PDF (one purchase gives you both formats!). This update is free for existing readers, and does not increase the price. You can buy it now on Gumroad. For those outside of the richest top 50 countries by GDP, there’s a 50% discount. The book has a changelog at the end of the “Introduction” chapter. Here’s the entry for this update: Added ePub file to the release. Thanks to Mike Lissner and Paolo Melchiorre for requesting and testing it. Upgraded to Python 3.9 and Django 3.2 and updated content to reflect changes. Added Mock Time section to the “Targeted Mocking” chapter, … -
Django 3.2 Update for “Speed Up Your Django Tests” Released
I released my book “Speed Up Your Django Tests” over a year ago, in May 2020. Since then, we’ve seen two major Django releases, including a whole bunch of test-related changes, some of which I worked on as part of the book. Today I’m releasing the first update for SUYDT. The update brings the existing content up to date with Python 3.9, Django 3.2, and some future changes for Django 4.0. It also includes some new sections on mocking time and parallelizing tests. And for those who with e-readers, it now comes as an ePub file, alongside the original flavour PDF (one purchase gives you both formats!). This update is free for existing readers, and does not increase the price. You can buy it now on Gumroad. For those outside of the richest top 50 countries by GDP, there’s a 50% discount. The book has a changelog at the end of the “Introduction” chapter. Here’s the entry for this update: Added ePub file to the release. Thanks to Mike Lissner and Paolo Melchiorre for requesting and testing it. Upgraded to Python 3.9 and Django 3.2 and updated content to reflect changes. Added Mock Time section to the “Targeted Mocking” chapter, … -
htmx - Carson Gross
htmx@htmx_org on TwitterhyperscriptBig Sky Softwaredjango-htmxRapid Prototyping with Django, htmx, and Tailwind CSSSupport the ShowThis podcast does not have any ads or sponsors. To support the show, please consider visiting LearnDjango.com, Button, or Django News. -
Custom Permission Classes in Django REST Framework
This article looks at how to build custom permission classes in Django REST Framework (DRF). -
A Guide to the Django ModelForm - Creating Forms from Models
Django ModelForms is a helper class that allows you to create a Form class from an existing Django model. It honestly sounds more complicated than it actually is to implement. Create a Django Model Add a model to models.py mysite > main > models.py from django.db import models # Create your models here. class Movie(models.Model): movie_title = models.CharField(max_length=150) release_year = models.IntegerField() director = models.CharField(max_length=100) movie_poster = models.ImageField(upload_to='images/', null=True) movie_plot = models.TextField() def __str__(self): return self.movie_title The example above is from How to use Django Models. The model contains CharFields, IntegerField, ImageField, and a TextField. The function at the bottom returns the movie's title as the display name in the admin so it's easy to identify each model object. Configure the project for media uploads mysite > mysite > settings.py MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') Add a URL for Django media file uploads in the settings if you have an ImageField or FileField in your models. mysite > mysite > urls.py from django.contrib import admin from django.urls import path, include from django.conf import settings #add this from django.conf.urls.static import static #add this urlpatterns = [ path('admin/', admin.site.urls), path('', include ('main.urls')), ] if settings.DEBUG: #add this urlpatterns … -
python manage.py HowDjangoWorks
Have you ever wondered how Django works and what components lie behind and what is happening when you run the application? You probably go to documentation or listen to good but lengthy talks given by core members of Django Framework. I wanted to stu... -
Book Review: Team Topologies
Team Topologies (Matthew Skelton and Manuel Pais, 2019) is, essentially, a book-length treatment of the Inverse Conway Maneuver. I recommend this book to folks looking to design or refactor product delivery organizations, especially those unfamiliar with the idea of aligning teams to delivery priorities. -
Tailwindcss: Fall in Love with Writing CSS Again for your Django Application
If you're a developer, chances are that you've been in this situation before. You're writing CSS for your Django app, and it's not really coming naturally to you. The code is looking sloppy and unorganized, so the whole project looks like a mess! Tha... -
GraphQL subscriptions in Django with Ariadne and Channels
In this post we will see how to add GraphQL subscriptions to Django with Ariadne and Channels, and what it takes to work with the Django ORM in an asynchronous context. What is Ariadne? Ariadne is a GraphQL library for Python, which offers also an integration for Django. GraphQL is a data query language which allows the client to precisely define what data to fetch from the server and combine data from multiple resources in one request. In a sense, this is what we always did with REST APIs, but GraphQL takes this a step further, pushing more control to the client. What is Django Channels? Channels is a library which adds, among other protocols, WebSockets capabilities to Django. Setup and sample models This mini tutorial assumes you have a Django project where you can install Django Channels and Ariadne. My demo project has a sample model named Order, as follows: from django.db import models from django.conf import settings class Order(models.Model): class State(models.TextChoices): PAID = "PAID" UNPAID = "UNPAID" date = models.DateField() state = models.CharField(max_length=6, choices=State.choices, default=State.UNPAID) user = models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE) To start off, with the virtual Python environment active, install Channels and Ariadne: pip install ariadne channels Next up, … -
How to Create Django Application Authentication (Sign up and Login)
Hello, and welcome to this simple but effective tutorial on how to create Django user sign-up and login page. In this tutorial we will learn how to use Django's pre-built user register form called 'UserCreationForm'. This built-in form also have a bu... -
Writing automated tests for your Django app | An introduction to continuous integration (CI)
Have you ever bought a pen and tried to write something on a random piece of paper to see if it works? why do you test it even when we all know it is a pen and pens are supposed to write stuff? You do that to ensure you do not pay for a faulty pen be... -
Django Debug Toolbar
Debugging Django Applications - Django Debug Toolbar In my previous post I showed you how to setup VSCode in order to debug Django applications. In this post, I will show you how to the Django Debug Toolbar and how to install it. The Django debug ... -
Django News - Django security releases 3.2.5 and 3.1.13 - Jul 2nd 2021
News Django security releases (3.2.5 and 3.1.13) Django versions 3.2.5 and 3.1.13 have been released. They fix one security defect with severity “high." As always, it is strongly recommended to update to the latest version of Django in your projects. djangoproject.com Python 3.9.6, 3.8.11, 3.7.11, and 3.6.14 Python 3.9.6 is the newest major stable release. Python 3.8.11 marks the first security-only release joining 3.7.11 and 3.6.14 in the security-only stage of their life cycles. blogspot.com Events DjangoCon US 2021 - Call for Proposals The online conference runs October 21st - 23rd. CFP closes on July 18. papercall.io Articles How to Start a Production-Ready Django Project Vitor from SimpleIsBetterThanComplex.com shows his approach for organizing Django projects these days. simpleisbetterthancomplex.com Built-in Permission Classes in Django Rest Framework A look at the 7 built-in permission classes in DRF. testdriven.io How to use Python’s HTTPStatus with Django - Adam Johnson A look at two different ways to use HTTPStatus in your Django code. adamj.eu YAGNI exceptions A look at several You Ain't Gonna Need It exceptions for Django apps. There are some things which really are easier to do earlier than later, and where natural tendencies or a ruthless application of YAGNI might neglect … -
Deploying Django Web App Using Heroku (Updated)
Heroku is one of the most popular hosting platforms for web applications. In this article, I will provide a step-by-step guide on how to deploy a Django web application in Heroku. Signup for Heroku if you don't have an existing account. Install the... -
Debugging Django Applications
Debugging Django Applications in VSCode All new programmers typically start with using console.log() statements in JavaScript or print and pprint statements in python to see what is going on in their code. In python, If you are using print to log o... -
Build a Custom User Registration Form in Django
Django framework comes with a UserCreationForm form that helps in creating user accounts quickly. By default, registration requires users to enter username, password and password confirmation. That's cool! This is all written by a built-in class tha... -
Learning Backend WebDev, Log #11 - Got a Django Certificate! Some Reflections
Been a few days since I wrote about Django. Last week was a roller coaster personally, so I took things slow. And then got back to a rhythm this week. Read more… (3 min remaining to read) -
How to use Python’s HTTPStatus with Django
A “magic number” is the anti-pattern of using a number directly rather than storing it in a descriptive variable name. In web code HTTP status codes are often used as magic numbers, perhaps because web developers memorize common codes such as 200 and 404. In Python, we can avoid such magic with descriptive references from the standard library’s http.HTTPStatus enum. Let’s look at two ways to use HTTPStatus in our Django code. 1. Creating Responses Django includes a bunch of HttpResponse subclasses for common status codes, but the list is deliberately non-exhaustive. If we need to return a status code for which a classes does not exist, we can use Python’s HTTPStatus with Django’s HttpResponse. For example, if one of our pages is unavailable due to legal reasons, so we want to return status code 451. We can do this with HttpResponse like so: from http import HTTPStatus from django.http import HttpResponse def taken_down(request): ... return HttpResponse( content, status_code=HTTPStatus.UNAVAILABLE_FOR_LEGAL_REASONS, ) If we find ourselves using a status code a lot in our project, we can create our own HttpResponse subclasses, as the documentation mentions. For example: from http import HTTPStatus from django.http import HttpResponse class HttpResponseLegallyUnavailable(HttpResponse): status_code = HTTPStatus.UNAVAILABLE_FOR_LEGAL_REASONS Additionally, … -
How to use Python’s HTTPStatus with Django
A “magic number” is the anti-pattern of using a number directly rather than storing it in a descriptive variable name. In web code HTTP status codes are often used as magic numbers, perhaps because web developers memorize common codes such as 200 and 404. In Python, we can avoid such magic with descriptive references from the standard library’s http.HTTPStatus enum. Let’s look at two ways to use HTTPStatus in our Django code. 1. Creating Responses¶ Django includes a bunch of HttpResponse subclasses for common status codes, but the list is deliberately non-exhaustive. If we need to return a status code for which a classes does not exist, we can use Python’s HTTPStatus with Django’s HttpResponse. For example, if one of our pages is unavailable due to legal reasons, so we want to return status code 451. We can do this with HttpResponse like so: from http import HTTPStatus from django.http import HttpResponse def taken_down(request): ... return HttpResponse( content, status_code=HTTPStatus.UNAVAILABLE_FOR_LEGAL_REASONS, ) If we find ourselves using a status code a lot in our project, we can create our own HttpResponse subclasses, as the documentation mentions. For example: from http import HTTPStatus from django.http import HttpResponse class HttpResponseLegallyUnavailable(HttpResponse): status_code = HTTPStatus.UNAVAILABLE_FOR_LEGAL_REASONS Additionally, … -
FullStack React & Django Authentication : Django REST ,TypeScript, Axios, Redux & React Router
As a full-stack developer, understand how to build an authentication system with backend technology and manage the authentication flow with a frontend technology is crucial. In this tutorial, we'll together build an authentication system using React ... -
1. Introduction to Django as a Framework
Welcome back people, let's make this brief and precise. Okay. Some of us already know Django, some of us don't, let's discuss what django is first. Folks, meet Django, Django, meet folks Django is a high-level Python Web framework that encourages rap... -
Octoprofile - the Django project
I am very happy to share with you the Django project I have been working on last 20 days, it's called an Octoprofile. Project Octoprofile displays the GitHub profile in a better way with Charts and sortable lists. Octoprofile collects the user infor... -
How I clone the Movement Pass service website of Bangladesh
Where does it come from? Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney Colle...