Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django Settings Patterns to Avoid
This post is an adapted extract from my book Boost Your Django DX, available now. It has a 50% discount for the Black Friday sale, until the end of Cyber Monday (28th Nov), plus a further 50% off for those outside the GDP top 50. Here are some potential mistakes made with Django settings that you can avoid. Don’t Read Settings at Import Time Python doesn’t make a distinction between import time and run time. As such, it’s possible to read settings at import time, but this can lead to subtle bugs. Reading a setting at import time will use or copy its initial value, and will not account for any later changes. Settings don’t often change, but when they do, you definitely want to use the new value. For example, take this views file: from django.conf import settings ... page_size = settings.PAGE_SIZE def book_list(request): paginator = Paginator(Book.objects.all(), page_size) ... page_size is set to the value of the setting once, at import time. It won’t account for any changes made in tests, such as with override_settings: from django.test import TestCase, override_settings class BookListTests(TestCase): def test_pagination(self): with override_settings(PAGE_SIZE=2): response = self.client.get(...) The previous view code would not use the changed PAGE_SIZE … -
Butter CMS - Jake Lumetta
ButterCMSButterCMS Job Openings@jakelumettaSupport the ShowThis podcast does not have any ads or sponsors. To support the show, please consider purchasing a book, signing up for Button, or reading the Django News newsletter. -
Django-related Deals for Black Friday and Cyber Monday 2022
Here are some Django-related deals for this year’s Black Friday (25th Nov) and Cyber Monday (28th Nov), including my own. My books My two books, Boost Your Django DX and Speed Up Your Django Tests, have 50% off their base prices. The deal stacks with the regional discount that offers a 50% discount for those living outside the GDP top 50. If you live in such a country, email me to get a total of 75% off the base prices. This discount is available until the end of Cyber Monday, “Anywhere on Earth” (AoE). That is, it’s live as long as it’s still Cyber Monday or before, in one time zone, anywhere on earth. Buy now: Boost Your Django DX Speed Up Your Django Tests (You can buy both in one transaction by clicking “Buy this” on one, then “Continue shopping” at the top right, which will let you add the other to your cart.) William Vincent’s Three Book Bundle William Vincent is the author of three fantastic Django books: Django for Beginners Django for APIs Django for Professionals He’s offering a 50% discount on the three book bundle, from $97 to $49. Buy it on Gumroad testdriven.io Four Course … -
Django News - 2023 Django Software Foundation Board Candidates - Nov 18th 2022
News 2023 DSF Board Candidates There are thirty candidates for the upcoming 2023 Django Software Foundation Board, the non-profit behind Django. DSF Individual Members vote on them. djangoproject.com Wagtail 4.1.1 Wagtail 4.1.1 fixes almost a dozen bugs. github.com Django Technical Board: Project Ideas, and beginning GSoC 2023. The 2023 Google Summer of Code has been announced and Django Fellow Carlton Gibson is soliciting input on project ideas. google.com Python 3.12.0 alpha 2 released Python 3.12.0a2 is the second of seven planned alpha releases. python.org Acceptable Use Policy · PyPI The Python Package Index (PyPI) added an Acceptable Use Policy. pypi.org Sponsored Ad Now Hiring Software Engineers Are you interested in building the next generation MLOPS Platform in Django? Apply today! Ampsight, Inc. is a small but quickly growing government services technology company located in Ashburn, Virginia, recently recognized by Inc. 5000 as one of the fastest growing companies in the United States. trinethire.com Articles Contributing to Django or how I learned to stop worrying and just try to fix an ORM Bug From attending the DjangoCon US sprints to tackling an ORM bug, Ryan Cheley walks us through the entire process. ryancheley.com Towards Inbox Zero: An update on Django's open … -
Development Cached Templates - Building SaaS with Python and Django #150
In this episode, I ran through a Python exercise on Exercism that focused on strings. Then we moved onto the homeschool app and fixed an issue with templates that were cached during development because of changes in Django 4.1. -
Intervista Pythonista - Ep 31
Python Milano presents Intervista Pythonista. We give a voice to Italian Pythonistas and get to know them closely with short interviews. Presented by Marco Santoni and Cesare Placanica. -
First impressions trying out Rome to format/lint my TypeScript and JavaScript
Rome is a new contender to compete with Prettier and eslint, combined. It's fast and its suggestions are much easier to understand. I have a project that uses .js, .ts, and .tsx files. At first, I thought, I'd just use rome to do formatting but the linter part was feeling nice as I was experimenting so I thought I'd kill two birds with one stone. Things that worked well It is fast My little project only has 28 files, but time rome check lib scripts components *.ts consistently takes 0.08 seconds. The CLI looks great You get this nice prompt after running npx rome init the first time: Suggestions just look great Easy to understand and needs no explanation because the suggested fix tells a story that means it's immediately easy to understand what the warning is trying to say. It is smaller If I run npx create-next-app@latest, say yes to Eslint, and then run npm I -D prettier, the node_modules becomes 275.3 MiB. Whereas if I run npx create-next-app@latest, say no to Eslint, and then run npm I -D rome, the node_modules becomes 200.4 MiB. Editing the rome.json's JSON schema works in VS Code I don't know how this … -
unittest’s new context methods in Python 3.11 (with backports)
Python 3.11 only made one change to unittest, but it’s a good one: context manager methods. These methods can simplify setup and teardown logic in many cases, such as dynamic use of unittest.mock. In this post we’ll look at a couple fo examples using the new methods, and a backport you can copy-paste into your projects, in plain and Django flavours. A time-saving example Take this test case, which uses my time-mocking library time-machine to fix the current microsecond to 0 (for whatever reason): import datetime as dt from unittest import TestCase import time_machine class ExampleTests(TestCase): def setUp(self): now = dt.datetime.now().replace(microsecond=0) self.traveller = time_machine.travel(now) self.traveller.start() self.addCleanup(self.traveller.stop) super().setUpClass() def test_microsecond(self): self.assertEqual(dt.datetime.now().microsecond, 0) It takes three steps to set up the mocking: Create a “traveller” by calling time_machine.travel(). Make it mock time by calling its start() start method. Schedule un-mocking by passing its stop() method to addCleanup(). This is verbose. Plus, it’s all too easy to too easy to forget the cleanup step, leading to test pollution. You can merge those three steps into one with Python 3.11’s enterContext() method: import datetime as dt from unittest import TestCase import time_machine class ExampleTests(TestCase): def setUp(self): now = dt.datetime.now().replace(microsecond=0) self.traveller = self.enterContext(time_machine.travel(now)) super().setUpClass() def … -
Python Type Checking
This article looks at what type hints are and how they can benefit you. We'll also dive into how you can use Python's type system for type checking. -
Moving data including deletions between the same Django app running in different environments
Moving data including deletions between the same Django app running in different environments Many projects use different environments to stabilize the code; they have a production environment which is actually seen by users, a stage where code is tested in an environment close to production and maybe several additional environments where more experimental code is published or developed, either on internal or protected webservers or maybe on the workstations of developers themselves. The same process may be desired for content; an environment where the content lives which is seen by users and other environments where the content can be changed without impacting the production environment. When using Django and the Django admin site there is no ready-made solution for doing this and maybe there shouldn’t be. Django’s serialization framework and its shortcomings for the use case outlined above Django comes with a serialization framework and with the dumpdata and loaddata management commands which can be used to dump and load data, e.g. to and from JSON. It’s also easily possible to specify a list of primary keys on the command line if you only want to dump a subset of the existing data. When loading this subset data which isn’t … -
Django News - Detecting N+1 Issues - Nov 11th 2022
Sponsored Ad Now Hiring Software Engineers Are you interested in building the next generation MLOPS Platform in Django? Apply today! Ampsight, Inc. is a small but quickly growing government services technology company located in Ashburn, Virginia, recently recognized by Inc. 5000 as one of the fastest growing companies in the United States. trinethire.com Events Python Web Conf 2023 CFP Open until Nov. 15 The 5th annual Python Web Conf will be hosted virtually from March 13-17, 2023. With sessions for mid-level and advanced developers alike, international experts will share cutting-edge presentations on topics including AI/ML, Big Data, CI/CD, Serverless, Security, Containers and more. Speakers of all backgrounds are welcome and encouraged to submit a talk. papercall.io PyCon US Online Experience Committee Volunteer Application PyCon US is introducing the Online Experience Committee to enhance the PyCon US virtual experience and boost engagement for our online attendees. If you are interested in volunteering, they are looking for people who are excited about online events. google.com DjangoCon US 2022 Official Photos Many, many photos of the event and all its participants. flickr.com Articles How Sentry uncovered an N+1 issue in djangoproject.com Using Sentry to detect N+1 issues in Python code and specifically on … -
Deploying a Django App to Fly.io
This tutorial looks at how to deploy a Django application to Fly.io. -
DjangoCon US 2022 Recap
DjangoCon US 2022DjangoCon Europe 2022 VideosAbout my proposal for the Django Core SprintsPersonal Thoughts on the Django Software Foundation Board’s Future Benchmarks for SQLite in DjangoSupport the ShowThis podcast does not have any ads or sponsors. To support the show, please consider purchasing a book, signing up for Button, or reading the Django News newsletter. -
Deploy Django + PostgreSQL on Fly.io
In this guide we will develop a Django Todo application locally and then deploy it on [Fly.io](https://fly.io) with a [Postgres production database](https://fly.io/docs/reference/postgres/). There are a number of steps needed to … -
Professionalism: You should maintain a transition file
When you change jobs, ideally you’ll have the opportunity to brief your successor directly. But that isn’t always possible: you might get fired or laid off, you might leave for another job without a clear successor named before your last day, you might have to take sudden medical leave, etc. Situations like that will be disruptive, it’s unavoidable, but a transition file will help minimize that disruption. -
A Python 3.11 "gotcha"
Recently at work I’ve been doing a bit of performance tuning on a service that’s getting ready to launch. It’s been built mostly on the tried-and-true principle of “first make it correct, then make it fast”, and really more like “then make it fast if necessary“. This is important because you generally want to have an idea of your performance goals up-front, and if you’re already hitting them then you should not spend a … Read full entry -
Django: Customizing how a model form renders fields
<![CDATA[ Django: Customizing how a model form renders fields I recently wanted to improve my form that contains a couple of ImageField fields. I wanted to display a small preview of the image to remind users what they saved for this particular model. Since I am using the Django Form API to render the form in a template without providing my own HTML, I couldn’t add more HTML to show the preview. Instead, what you can do is to provide custom “widgets” for some of the fields in your model form. I will use my implementation as an example, but you could use this same approach for other form fields to customize how they get rendered. Initial setup To get the ability to customize the widgets, you need to do a bit of configuration in the settings.py. You need to add 'django.forms' to your INSTALLED_APPS and add this line: FORM_RENDERER = 'django.forms.renderers.TemplatesSetting' TimonWeb has a bit more info about this. Creating your custom template The next step is to create your template in the templates directory. Creating a custom widget template is easier than it sounds since you can look at the base widget templates in Django to get the … -
Django News - Django bugfix release: 4.1.3 - Nov 4th 2022
News Django bugfix release: 4.1.3 Django 4.1.3 fixes a bug in 4.1.2 and adds compatibility with Python 3.11. djangoproject.com 2023 DSF Board Nominations (Final Day!) Applications for the 2023 Django Software Foundation Board of Directors are now open until November 4th. Please consider running. djangoproject.com Sponsored Ad Now Hiring Software Engineers Are you interested in building the next generation MLOPS Platform in Django? Apply today! Ampsight, Inc. is a small but quickly growing government services technology company located in Ashburn, Virginia, recently recognized by Inc. 5000 as one of the fastest growing companies in the United States. trinethire.com Events Become a PyCon US 2023 Volunteer! There are many ways to get involved if you are interested in serving the community and meeting others as part of the team who makes the conference possible! blogspot.com Articles How to Handle Django Forms within Modal Dialogs How to use django-crispy-forms with htmx to provide a form with server-side validation in a modal dialog. blogspot.com Static-Dynamic Content With In-Memory SQLite Andrew Godwin's overview of mixing static content with in-memory SQLite without leaving Django behind. aeracode.org Django Performance Improvements - Part 4: Caching in Django Applications The 4th in a series on improving performance in … -
Reusable cookie consent app for Django
Reusable cookie consent app for Django We at Feinheit have been working on a cookie consent app for some time. Why and what? There are many many solutions in this problem space already. We have used several scripts in the past. Some are simple banners or popups which only inform users that cookies are being used. It is our view and belief that this isn’t sufficient to fulfil the legal obligations imposed by the GDPR and other comparable legislations. We wanted a way to ask for consent and only embed any third party scripts after the consent has been given, not use some other tool which only comes into action after e.g. the Google Analytics scripts already have been loaded. Accepting only essential cookies is made very annoying by some cookie banners. They drown users in options and nudge (or maybe coerce) them towards accepting all cookies. The banner buttons are inspired (stealed) from Twitter, we think it’s nice to offer as little options as possible. Embedding third party content Also, we wanted to integrate a solution for embedding content from third party sites (e.g. Vimeo, Mailchimp and friends) where consent was asked as well when users only accept essential … -
Exercism and PDF Page Numbering - Building SaaS with Python and Django #149
In this episode, we started to work on Python learning problems on Exercism. Then I added page numbers to PDFs on my homeschool app. -
Django News - Python 3.11 released - Oct 28th 2022
News 2023 DSF Board Nominations Applications for the 2023 Django Software Foundation Board of Directors are now open until November 4th. Please consider running. djangoproject.com What does the DSF Board actually do? An overview of the Django Software Foundation Board and its duties. djangoproject.com Python Release Python 3.11.0 Python 3.11.0 is the newest major release of the Python programming language, and it contains many new features and optimizations. python.org Python 3.12.0 alpha 1 released Python 3.12.0a1 is the first of seven planned alpha releases for the next version of Python. python.org Python Core Development Sprint 2022: 3.11 and beyond! Overview of a Python 3.11 core sprint. Something we could potentially add to Django itself, too. python.org django-developers: Changing the role of the Technical Board Thoughts from Andrew Godwin about the Django Technical Board's future. google.com Sponsored Ad Django Hosting by CodeRed Cloud At CodeRed, we’re striving to build the world’s easiest Django hosting platform. Go from polls tutorial to production in just a few minutes. Get started with a free account which includes a MariaDB or Postgres database, static + media hosting, and everything you need to run a Django site. No AWS, S3, Docker, or 3rd-party services required! codered.cloud … -
Deploying a Flask App to Render
This tutorial shows how to deploy a Flask application with PostgreSQL to Render. -
HorseRecords - Andy Ide
HorseRecords@andyide40 on Twitterdjangoandy.comdjango-autocomplete-lightdjango-qAssets in Django without losing your hair by Jacob Kaplan-Moss @Pycon US 2019Support the ShowThis podcast does not have any ads or sponsors. To support the show, please consider purchasing a book, signing up for Button, or reading the Django News newsletter. -
django-upgrade Mega Release 1.11.0
I just released version 1.11.0 of django-upgrade, a tool for automatically upgrading your Django project code. This release contains a lot of new features and fixes, thanks to new contributors including those at the Djangocon Europe sprints. Let’s look at the top changes. New admin.site.register() fixer Originally the Django admin required you to first define a ModelAdmin class, and then later register Model classes to use it with admin.site.register(): from django.contrib import admin class MyCustomAdmin(admin.ModelAdmin): ... admin.site.register(MyModel1, MyCustomAdmin) admin.site.register(MyModel2, MyCustomAdmin) With this format, the register() calls can become quite separated from the admin classes. In more complicated scenarios, you might also miss exactly which Model classes are registered to an admin class. To solve these problems, Django 1.7 (September 2014!) added the admin.register() class decorator: from django.contrib import admin @admin.register(MyModel1, MyModel2) class MyCustomAdmin(admin.ModelAdmin): ... django-upgrade can now automatically upgrade from the first form to the second: from django.contrib import admin +@admin.register(MyModel1, MyModel2) class MyCustomAdmin(admin.ModelAdmin): ... -admin.site.register(MyModel1, MyCustomAdmin) -admin.site.register(MyModel2, MyCustomAdmin) This works with various forms of admin.site.register() calls, and with GIS admin aliases as well. Thanks to Thibaut Decombe for contributing this feature. New @admin.action() and @admin.display() fixers The Django admin has two special kinds of functions: actions and display functions. … -
About my proposal for the Django Core Sprints 🌅
The story of how the proposal to organize sprints on the Django core was born and how I proposed it during the past DjangoCon US 2022 in San Diego to various components of the Django community.