Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Chapter 11: Form Fundamentals
Sometimes in theclean(), cleanFOO() or save() methods of a Django form, we need to have additional form instance attributes available. A sample case for this is having the request.userobject available. Here is a simple taster-driven example. -
One Database Transaction Too Many
Have you ever wondered how bugs are born? I'm not talking about the trivial kind you can catch with simple unit testing. I'm talking about bugs that may not be apparent on first sight, but are so obvious in retrospect. This is a story about how I accidentally sent hundreds of users messages they got paid when they didn't! What it feels like when you realized you made a mistakeIllustration by Milica Vezmar Basara Table of Contents The Story Creating a Payout Sending Notifications Working in Bulk The Bug Nested Transactions Remedies Assert Atomic Block Durable Transaction Sending Signal on Commit Using a Queue Testing Testing with Django Testing with Pytest Thoughts on Django Signals The Story We have a process in the system where we pay out money to merchants and other types of users. The payout process is a pretty big deal for most users because this is how they get paid. Creating a Payout To facilitate the payout process we have a Django model called PayoutProcess. To create a new payout we use a function that looks roughly like this: from __future__ import annotations from django.db import model, transaction as db_transaction class PayoutProcess(models.Model): #... fields @classmethod def … -
Tổng quan về xác thực người dùng trong Django
Django đi kèm với hệ thống xác thực người dùng. Nó xử lý các tài khoản người dùng, các nhóm người dùng, quyền và phiên làm việc của người dùng dựa trên cookie. Tổng quan Hệ thống xác thực của Django xử lý các xác thực và ủy quyền người dùng. Xác thực... -
Mvt Pattern Of Django
In this post, we will discuss the MVT pattern on Django. The MVT (Model View Template) is a software design pattern. It is a collection of three important components Model View and Template. Although Django follows the MVC pattern but maintains its o... -
Backend Engineer Interview Script
Dwight Schrute, Assistant *to* the Regional Manager. Dunder Mifflin Inc. Credit: NBC. Last month I’ve written a post with Django-specific interview questions. That post is about verifying a candidate’s depth of knowledge with Django. This post is about less specific questions I ask a candidate. Before proceeding to the Django specific ones. If I do proceed after all. In case the candidate does not have any Django-specific experience, what’s the point? These questions do not look for specific answers. Rather the aim is to open up a discussion. So the questions are more in the form of how or why rather than what. And no. How do you describe yourself? is not one of these questions. If you ever get that question, the only correct answer is that by Dwight Schrute as shown above. The questions in this article revolve around: improving web application response time designing authentication handling asynchronous work / task queues HTTP REST API design 1. Server response time Q: In the context a dynamic “data driven” web application, how would you decrease a page’s response time? Asking this should allow the candidate to come up with multiple answers. Among the common answers you should note the … -
How to test a Django ModelForm
What is a ModelForm in Django? ModelForm in Django is a convenient abstraction for creating HTML forms tied to Django models. Consider the following Django model: from django.db import models from django.contrib.auth.models import User class Invoice(models.Model): class State(models.TextChoices): PAID = "PAID" UNPAID = "UNPAID" CANCELLED = "CANCELLED" user = models.ForeignKey(to=User, on_delete=models.PROTECT) date = models.DateField() due_date = models.DateField() state = models.CharField(max_length=15, choices=State.choices, default=State.UNPAID) def __str__(self): return self.user.email To create a form for this model so that we can save and edit invoices in a view, we can subclass ModelForm as follows: from django import forms from .models import Invoice class InvoiceForm(forms.ModelForm): class Meta: model = Invoice fields = ["user", "date", "due_date", "state"] Here we create an InvoiceForm tied to Invoice. This form will expose the following fields in the form: user date due_date state Once we create a ModelForm, we can use it in creation/editing Django views. For an example of the usage, check out the documentation. In this post we focus only on testing the form without interacting with the view layer. (For an example test of a form in the context of a view see Testing an inline formset in Django) How to test a Django ModelForm Testing the … -
Simple Guide for Django Admin Interface
Building a Full Stack Application is challenging and fun. By building the full stack application we get to learn so many things like database, routing, template, etc. But there the one most important thing we get to learn is managing data with the he... -
Working with Geo🌎Django
GeoDjango is a built-in application that is included as a contrib module in Django. It’s actually a complete framework itself that can also be used separately from Django. It provides a toolbox of utilities for building GIS web applications. Purpose ... -
Send emails with Django and Gmail , a better way
In this post I want to talk about how can we send emails using Django and Gmail, I read a lot of articles about this but none of them is working for me, this is my way of doing this Setup Django 💚 first let's install django pip install django ... -
The "Basics" of adding PayPal payments to Django, server and client-side
in this article will show a basic way on how to implement the Paypal payments using the checkout API on your Django project, for this I will create an e-learning website where the user can purchase courses first clone this codebase from GitHub cl... -
The "Basics" of adding PayPal payments to Django, server and client-side
in this article will show a basic way on how to implement the Paypal payments using the checkout API on your Django project, for this I will create an e-learning website where the user can purchase courses first clone this codebase from GitHub cl... -
How to Decouple Your App From its Operating System with Docker
We regularly update and improve our upgrades and sustainability service offerings at Caktus, and a recent upgrade for a client precipitated a solution that I felt might be worth sharing. At Caktus, the preferred approach for addressing upgrades and sustainability is to make incremental updates to a project over time, trying to keep both Django and the servers themselves on a long-term support version. These are select versions of Django and Ubuntu, for example, that generally have much longer support periods than other versions, i.e., they are a good fit for applications that you will need to continue maintaining well into the future. We continue to host large projects for our customers that we began as early as 2010, and we've applied this methodology throughout the past decade to keep systems updated and mitigate risk. One such project currently includes upwards of 40 servers (across several environments), all provisioned automatically with a tool built for that purpose. This client also requires the systems to be run on physical hardware that we also help manage, rather than in the cloud. Upgrading Python but Not the OS Recently we wanted to upgrade the version of Python used for this application, but weren't … -
Future of Jazzband
There were a number of requests to financially support Jazzband over the years and many questions arose around how to continue to grow Jazzband without risking the maintenance of the existing projects. So to support the continued development of Jazzband, an application to the Fiscal Sponsorship program of the Python Software Foundation was submitted earlier this year. And the good news is: Jazzband has been accepted! That will allow Jazzband for the first time to receive donations from its individual and corporate users to offset infrastructure cost and work on plans for the future. Here’s the donation link: https://jazzband.co/donate -
Stats after 5 years
The past few years at Jazzband went by so quick, so here’s a quick overview: Members ~1,350 unique members over the years > 900 members currently Projects ~ 55 current projects, 10 projects have left again ~ 20 projects are currently being proposed Activity 160 people pushed ~6,000 commits 22,000 stars from 14,500 people! Issues 3,000 new issues from ~2,000 people 17,000 issue comments by 4,000 people 600 people closed 2,500 issues Pull requests 3,000 new pull requests from ~ 1,000 people 3,000 pull request comments from 300 people 3,500 closed pull requests by 270 people Thank you all for your work! Feel free to contact Jazzband if you’re interested in learning how these numbers were calculated. -
Project teams
Five years ago, Jazzband was launched to help Python projects that struggle to continue maintenance for various reasons, e.g. when original authors don’t have time anymore to continue the maintenance. Jazzband has grown quite a bit since then: over 1300 people in total have decided to become members over the past 5 years, of which over 900 current members remain as of writing this post. At the same time over 50 projects have been transferred to Jazzband and adopted the Jazzband guidelines, Code of Conduct and project maintenance patterns. A handful of projects decided to leave Jazzband again for a number of reasons, which provided plenty of experience for how to improve the Jazzband processes and documentation. It’s clear that Jazzband can be better and needs to adapt to the members’ needs. One area in particular was brought up often: the communication between those members that are interested in contributing to only specific and not all of the existing Jazzband projects. So as a first step to fix this: Jazzband introduce self-service project teams! What are project teams? Project teams are optional, self-service groups of Jazzband members that are interested in working on specific projects. Project teams are based on … -
Django News - Django 3.2.4, Wagtail 2.13.1, and Python 3.10.0b2 released - Jun 4th 2021
News Django 3.2.4, 3.1.12, and 2.2.24 security release In accordance with our security release policy, the Django team is issuing Django 3.2.4, Django 3.1.12, and Django 2.2.24. As always, the best way to keep your Django apps secure is to update to the latest version promptly. djangoproject.com Wagtail 2.13.1 bugfix release Wagtail 2.13.1 is a bugfix release. wagtail.io Python 3.10.0b2 release Python 3.10 is still in development. 3.10.0b2 is the second of four planned beta release previews. blogspot.com Sponsored Link Seeking 5 beta users for feedback to improve Django Server Management SaaS project This may be a bad idea. I'm seeking 5 fellow Django devs to be beta users for the Django equivalent of Laravel Forge or Rails Hatchbox. If you're highly opinionated and enthusiastic about this area, go to http://bit.ly/gd-seeking-beta (notion doc) so I can get your feedback. greendeployhq.com Articles Git Cheat Sheet – 50 Git Commands You Should Know Git is a distributed version control system that helps developers collaborate on projects of any scale. Linus Torvalds, the developer of the Linux kernel, created Git in 2005 to help control the Linux kernel's development. What is a Distributed Version Control System? A distributed version control system is a … -
Understanding Django Application LifeCycle.
Understanding the flow of the application is an important part of application development. Flow like when user hit a particular URL then, what action needs to be taken, what type of response we should give back to the user and all. There are many imp... -
Permissions in Django Rest Framework
This article looks at how permissions work in Django REST Framework. -
The art of the SWAG
Sometimes, it’s more important to be able to produce a quick estimate than it is to produce a good one. In those cases, reach for the SWAG: the Simple Wild-Ass Guess. To a large degree making a (good) SWAG is an intuitive process, but I’ve tried to unpack what’s happening in that short moment and give some thoughts about when a SWAG is appropriate, and how to give one. -
How to deploy your Django App on Heroku
Hello Devs, Today I'm going to tell you how can you upload your Django project on Heroku in just simple steps.. First of all, install some modules :- pip install django-heroku pip install gunicorn pip install whitenoise Now add some scripts in ... -
DRF authentication with custom user models
I decided to write this article because of the challenges I faced when working with DRF authentication especially with a custom user model. I was frustrated at some point but with the help of googling, stack overflow and other friends who helped me t... -
Does My Site Work?
Full show notes are available at https://www.mattlayman.com/django-riffs/13. -
Episode 13 - Does My Site Work?
On this episode, we will discuss how you can verify that your site works and continues to work. We’re digging into automated testing and how to write tests for your Django apps. Listen at djangoriffs.com or with the player below. Last Episode On the last episode, our focus was on static files. Static files are vital to your application, but they have little to do with Python code. We saw what they are and what they do. -
DjangoCon Europe 2021 Sale of “Speed Up Your Django Tests”
I released my book Speed Up your Django Tests (SUYDT) just over a year ago, on the 18th May. It’s had a great reception, with 379 customers so far, many writing in to say how it has improved their test suites’ performance and readability. Additionally, this week I’m speaking at the second virtual DjangoCon Europe. My talk is at 9:15 am on Friday, on a topic related to the book: Speed up your tests with setUpTestData. If you’re attending, I look forward to seeing you there! (It’s still possible to buy tickets, and I believe it will be during the conference.) To celebrate these two occurrences, I’m offering a 33% discount on the list price of SUYDT. This takes it from $49 to $32, licensed for up to three developers. The discount lasts until the final day of DjangoCon Europe, Sunday the 6th June, “anywhere on Earth”. It also stacks with the regional discount of 50% off for those who live outside the GDP top 50. Find out more and buy on Gumroad. The current edition is based on Django 3.0 (and older). I’m partway through updating the content for changes up to Django 3.2, and should publish the update … -
DjangoCon Europe 2021 Sale of “Speed Up Your Django Tests”
I released my book Speed Up your Django Tests (SUYDT) just over a year ago, on the 18th May. It’s had a great reception, with 379 customers so far, many writing in to say how it has improved their test suites’ performance and readability. Additionally, this week I’m speaking at the second virtual DjangoCon Europe. My talk is at 9:15 am on Friday, on a topic related to the book: Speed up your tests with setUpTestData. If you’re attending, I look forward to seeing you there! (It’s still possible to buy tickets, and I believe it will be during the conference.) To celebrate these two occurrences, I’m offering a 33% discount on the list price of SUYDT. This takes it from $49 to $32, licensed for up to three developers. The discount lasts until the final day of DjangoCon Europe, Sunday the 6th June, “anywhere on Earth”. It also stacks with the regional discount of 50% off for those who live outside the GDP top 50. Find out more and buy on Gumroad. The current edition is based on Django 3.0 (and older). I’m partway through updating the content for changes up to Django 3.2, and should publish the update …