Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Sentry Setup - Building SaaS #166
In this episode, I finished the email sending job, then determined which issues will be needed before launching the product. Once we crafted the short list, I added an integration with Sentry. -
Sentry Setup - Building SaaS with Python and Django #166
In this episode, I finished the email sending job, then determined which issues will be needed before launching the product. Once we crafted the short list, I added an integration with Sentry. -
How ruff changed my Python programming habits
How ruff changed my Python programming habits ruff isn’t just a faster replacement for flake8, isort and friends. With other Python-based formatters and linters there’s always a trade off between development speed (waiting on git commit is very boring) and strictness. ruff is so fast that enabling additional rules is practically free in terms of speed; the only question is if those rules lead to better, or maybe just to more correct and consistent code. I have long been using pre-commit, and even longer flake8, black, isort. I have written a piece about flake8 and the value of standards almost 9 years ago and have continued moving in the mentioned direction ever since. These days I have enabled a wide variety of rules. I’m not sold on all of them (looking at you, pylint) and I’m definitely not of the opinion that rules which I’m not using currently are worthless. I didn’t even know most of these rules before starting to use ruff, and ruff making them easy and painless to use (without a measureable performance penalty) has certainly lead to me annoying my coworkers with a growing set of enabled rules. Rules The current ruleset and some justifications for … -
Easy as Pie: Setting Up Dokku for Your Personal Project
IntroductionApplication Platform in the CloudAre you looking for a simple and efficient way to deploy your personal project without the complexities of traditional server management? Look no further than Dokku! In this tutorial, we’ll walk you through the seamless process of setting up Dokku for your personal project. By the end of this article, you’ll be amazed at how easy it is to get your application up and running in no time.What is Dokku?Dokku is a lightweight open-source platform that allows you to deploy and manage applications using Docker containers. Often referred to as “Docker-powered Heroku,” Dokku takes the simplicity of Heroku’s deployment model and combines it with the flexibility and power of Docker. With Dokku, you can deploy web applications, microservices, and various other types of projects effortlessly.PrerequisitesBefore we begin, make sure you have the following prerequisites in place:A personal project: Prepare your web application or project that you want to deploy using Dokku.A server: You will need a remote server or a VPS (Virtual Private Server) with a fresh installation of Ubuntu 20.04 or later.A domain: Purchase a domain name (e.g., example.com) from a domain registrar of your choice.DNS settings: Ensure you have access to your domain’s DNS … -
Weeknotes (2023 week 29)
Weeknotes I have mainly done work in private projects this week. Not much to talk about. Except for the ZIP file content-type bug which was interesting enough to justify its own blog post. Releases django-cabinet 0.13: I converted the package to use ruff, hatchling; started running CI tests using Python 3.11. The internals of the Django admin’s filters have changed to allow multi-valued filters, this has required some changes to the implementation of the folder filter. I opted to using a relatively ugly django.VERSION hack; but that’s not too bad since such branches will be automatically removed by the awesome django-upgrade. I would have tried finding other ways in the past but now that old compatibility code can be removed by a single run of django-upgrade (respectively pre-commit) there really is no point to doing it in a different way. -
Django News - DjangoCon US and AU 2023 programs are up! - Jul 21st 2023
News Python Web Conf 2023 Talks + Tutorials available on YouTube Watch 80 talks, tutorials, and socials from Python Web Conf 2023 on Six Feet Up's YouTube channel. Explore videos about Python, Django, Kubernetes, AI/ML, Big Data, CI/CD, Serverless, Security, Climate Tech, and more. youtube.com PyCharm & DSF Campaign 2023 Each year, our friends at JetBrains, the creators of PyCharm, run an incredible deal. You get a 30% discounted year of PyCharm, AND the DSF gets 100% of the proceeds. Plus, get one free month of access to JetBrains Academy, which has courses like Intro to Django, SQL, Git, and more! djangoproject.com Django Software Foundation DSF Board monthly meeting, July 14, 2023 Meeting minutes for DSF Board monthly meeting, July 14, 2023. djangoproject.com Updates to Django Updates to Django From Django Review and Triage Team Member Sarah Boyce... Last week we had 20 pull requests merged into Django by 12 different contributors - including 5 first time contributors! Congratulations to Tushar, Ryan Chausse, Cauê Thenório, Amir Karimi and Priyank Panchal for having their first commits merged into Django - welcome on board! Some highlights include: - updating QuerySet.bulk_create() to retrieve primary keys when updating conflicts (#34698) - adding documentation on … -
Email Templates - Building SaaS #165
In this episode, we added the prompt email that will be the primary way of connecting to users for our email-based journaling service. I spent a fair amount of time thinking about copy writing to craft a compelling email that will resonate with users. Also, I made a bunch of silly mistakes and to keep correcting myself, so this is a good example of programming humility too. -
Email Templates - Building SaaS with Python and Django #165
In this episode, we added the prompt email that will be the primary way of connecting to users for our email-based journaling service. I spent a fair amount of time thinking about copy writing to craft a compelling email that will resonate with users. Also, I made a bunch of silly mistakes and to keep correcting myself, so this is a good example of programming humility too. -
Django Deployments - Eric Matthes (Ep108 Replay)
django-simple-deployPython Crash Course recommended readingsPython Crash Course bookPython on Azure 4-Part Series with CarltonLocust.io: Open source load testing toolShameless PlugsLearnDjango.comButtonDjango News newsletter -
Django REST Framework Authentication with Auth.js
This tutorial looks at how to add authentication to Django REST Framework and integrate it with Auth.js. -
Serving ZIP files using Django
Serving ZIP files using Django I have generated ZIP files on the fly and served them using Django for a time. Serving ZIP files worked well until it didn’t and browsing StackOverflow etc. didn’t produce clear answers either. The development server worked fine, but gunicorn/nginx didn’t. In the end, I had to change content_type="application/zip" to content_type="application/x-zip-compressed". I still don’t know what changed and I have only theories why that’s necessary, but maybe it helps someone else. Sometimes it’s better to be dumber about it. -
Django News - 10 Merged PRs into Django Core This Week! - Jul 14th 2023
News Python 3.12.0 beta 4 released Python 3.12.0 beta 4 is the final of four beta release previews. We strongly encourage maintainers of third-party Python projects to test with 3.12 during the beta phase and report issues found to [the Python bug tracker (https://github.com/python/cpython/issues) as soon as possible. blogspot.com Updates to Django Updates to Django From Djangonaut Program Member Anvansh Singh. Last week, the Django community experienced 10 merged pull requests, accompanied by the exciting debut of remarkable first-time contributors Gregor Jerše and davidolz. Their impactful entrance is warmly embraced by the community! Gregor Jerše made a significant first contribution by improving accessibility for screen reader users, associating form fields with their help text using aria-describedby. This change enhances navigation and understanding of the form. If you have a custom aria-describedby attribute defined in a form widget, please read the updated documentation to take advantage of the improved accessibility for Django 5.0. Other notable contributions included Mariusz Felisiak's closure of a 15-year-old ticket (#9602) by adding a new method AdminSite.get_model_admin which returns an admin class for the given model class. Amazing! Want to make a contribution? Head over to https://code.djangoproject.com/query, pick a ticket, and start working. You may be the … -
Weeknotes (2023 week 28)
Weeknotes (2023 week 28)Releases html-sanitizer 2.2: Made the sanitizer’s configuration initialization more strict. Strings cannot be used anymore in places where the sanitizer expects a set (resp. any iterable). It’s useful that strings are iterable in Python and I wouldn’t want to change that, but the fact that ("class") is a string and not a tuple makes me sad. The fact that tuples are created by , and not by () will always trip up people. feincms3-language-sites 0.1: The version number is wrong but whatever. I’m certainly happy with the state of things. The big change in 0.1 is that Page.get_absolute_url no longer generates protocol-relative URLs. Depending on the value of SECURE_SSL_REDIRECT it automatically prepends either http: or https:. django-authlib 0.15: django-authlib’s admin Single Sign On module now supports a hook to automatically create staff users when a matching user doesn’t exist already. I don’t plan to use this functionality myself and I have recommended people to implement the functionality themselves using the tools in django-authlib if they need it, but the change was so small and well-contained that adding it to the core made sense to me. pipx inject We learned that pipx seems to remember injected packages even … -
Django: Clean up unused code with Vulture
As projects evolve, old functionality gets removed. Often such deletions are incomplete, leaving in their wake unused functions, classes, and other code objects. Unused code is clutter that brings no joy: it hinders comprehension, taxes codebase-wide quality improvements, and can sometimes lead to errors if later used. In an ideal world, test coverage data would reveal unused code, since a perfect test suite has 100% coverage of all features. But most projects don’t live in the ideal world, so unused code detectors exist. These tools use static analysis and heuristics to find probably-unused code, which you can then decide whether to remove. Such tools cannot be certain because Python makes it impossible to be sure that an object isn’t used. Objects can always be referenced with dynamically-constructed names, such as through globals(): def dynamic_about(request): page = request.GET.get("page", "company") if page not in {"company", "team", "..."}: page = "company" return globals()[f"about_{page}"](request) def about_company(request): ... Normally projects don’t have much dynamic dispatch like this, but it’s always a possibility. That’s why you need to review findings from an unused code detector before acting on it. Enter the Vulture Vulture is a popular unused code detector for Python. It analyzes the Abstract Syntax … -
FastAPI with Async SQLAlchemy, SQLModel, and Alembic
This tutorial looks at how to configure SQLAlchemy, SQLModel, and Alembic to work with FastAPI asynchronously. -
Django News - Django security releases issued: 4.2.3, 4.1.10, and 3.2.20 - Jul 7th 2023
News Django security releases issued: 4.2.3, 4.1.10, and 3.2.20 These releases address a new security issue. All users of Django are encouraged to upgrade as soon as possible. djangoproject.com Announcing the 2023 Python Software Foundation Board Election Results! Congratulations to the 5 new members. blogspot.com PyCharm & DSF Campaign 2023 In collaboration with JetBrains, Django Software Foundation (DSF) is running a fundraiser from July 3rd to July 23rd, offering a 30% discount on a year of PyCharm, with all proceeds supporting DSF. Purchasing also grants a free month of JetBrains Academy access with courses like Django, SQL, and Git. djangoproject.com Updates to Django Updates to Django From Django Review and Triage Team Member Sarah Boyce... Last week we had a massive 20 pull requests merged into Django by 11 different contributors - including 2 first time contributors! Congratulations to Jonathan Weth and Cerebro Cerberus for having their first commits merged into Django - welcome on board! Changes this week include adding support for GDAL 3.7 and dropping support for GDAL 2.2 and 2.3. Support for GEOS 3.6 and 3.7 has also been dropped. These are stated in the backwards incompatible changes of 5.0. Also, from Django 5.0, the force_insert argument … -
Django REST Framework (Replay)
DRF Google GroupDjangoCon 2018 Talk: Finally Understand User Authentication in DRFDRF Official Documents: Authenticationdjango-cors-header packageSwagger vs OpenAPIAPI StarStarletteGraphQL vs RESTSPONSORING OPTIONSDRF SponsorsDjango Software FoundationSHAMELESS PLUGSLearnDjango.comCarlton's website Noumenal -
Django: Flush out test flakiness by randomly ordering QuerySets
Sometimes code depends on the order of a QuerySet whilst not specifying an order. This can lead to random, flaky test failures because databases can return rows in any order when none is specified. The problem is made worse by some databases, notably PostgreSQL, which nearly always return rows in insert order, but occasionally use a different order when a table has had recent deletions. For example, take this test: from django.test import TestCase from example.models import Book from example.tasks import import_books class ImportBooksTests(TestCase): def test_success(self): import_books("sutherland.csv") books = Book.objects.all() assert books[0].name == "Transport for Humans" assert books[1].name == "Alchemy" The assertion block depends on the order of books. Unless the model has a Meta.ordering attribute, the database can return rows in any order. This test will occasionally, even rarely, fail due to a mismatch of books[0].name. The simplest fix is to specify an ordering: from django.test import TestCase from example.models import Book from example.tasks import import_books class ImportBooksTests(TestCase): def test_success(self): import_books("sutherland.csv") - books = Book.objects.all() + books = Book.objects.order_by("id") assert books[0].name == "Transport for Humans" assert books[1].name == "Alchemy" David Winterbottom’s post Patterns of flakey Python tests lists unspecified QuerySet ordering as a known flakiness-inducing pattern. He gave a … -
Django: A version of json_script for pre-serialized JSON strings
Django’s json_script template filter is a convenient and safe way to pass a larger amount of data to JavaScript. I covered it in my post last year How to Safely Pass Data to JavaScript in a Django Template. I found an interesting use case for json_script in my client Silvr’s project. The view had a pandas DataFrame that needed passing through the template to a chart-drawing JavaScript function. The default json_script wouldn’t work with pandas’ JSON output, so I created a custom version. pandas provides DataFrame.to_json() for converting a DataFrame to a JSON string. This method is convenient but its output is still not safe against HTML injection—it needs the escaping that json_script performs. But json_script only accepts an object to turn into a JSON string, and then escape - it cannot operate on a pre-serialized JSON string. You could add the escaping with a chain of: DataFrame.to_json to convert to a JSON string json.loads() to unserialize the result json_script on the result, to re-serialize and escape the result But the repeated serialization is wasteful and would take non-negligible time with large data. Rather than do that, I made a custom template filter that was a modified copy of json_script … -
Weeknotes (2023 week 26)
Weeknotes (2023 week 26)Releases I released updates to a few of my packages; I have continued converting packages to hatchling and ruff while doing that. New releases in the last two weeks include: django-tree-queries 0.15: Added a new function, .without_tree_fields() to the queryset which can be used to avoid the .with_tree_fields(False) boolean trap warning. feincms3-cookiecontrol 1.3.1: This small update allows replacing the feincms3 noembed.com oEmbed code using other libraries such as micawber which support a wider range of URLs while still gating the embed behind users’ explicit consent. feincms3-downloads 0.5.3: Updated translations. django-ckeditor 6.6.1: Updated the bundled CKEditor 4 and merged a pull request adding better integration with Django admin’s dark mode. django-js-asset 2.1: Just basic maintainability and packaging updates. The JS() implementation itself is untouched since February 2022. html-sanitizer 2.0: Not really a backwards incompatible change (at least not according to the tests); I just wanted to avoid 1.10 and go directly to 2.0 this time. GitHub projects We are using GitHub project boards more and more. It definitely isn’t the most versatile way of managing projects but it sort-of hits the sweet spot for us. [I’m mostly happy with it, and it seems to me that applying the … -
Django News - Wagtail Roadmap - Jun 30th 2023
News Introducing the Wagtail Roadmap Curious what's next for Wagtail? There's a roadmap for that. wagtail.org Deprecation of bdist_egg uploads to PyPI PyPI will stop accepting .egg uploads starting August 1, 2023. If you maintain and packages on PyPI, you'll want to know this. pypi.org Updates to Django Updates to Django From Django Review and Triage Team Member Sarah Boyce... Last week we had 10 pull requests merged into Django by 8 different contributors - including 1 first time contributor! Congratulations to Yaser Amiri for having their first commit merged into Django - welcome on board! Now, from Django 5.0, @sensitive_variables and @sensitive_post_parameters supports async functions! Are you excited to contribute but not know where to start? Maybe you're interested in migrations? You could add logging of applied/unapplied migrations #24800 and then you'd be perfect to add contributor documentation for django.db.migrations #24989! Look forward to welcoming you on board! github.com Sponsored Link Learn More About our Django Services At HackSoft, we offer expert Django software development, consultation and support, to help you build robust and scalable software. hacksoft.io Articles COUNTing is hard: A tale of types in SQL and Django The tale of an ORM bug that took several hours … -
Accounts and Email - Building SaaS #164
In this episode, I planned to do the work of sending email prompts for the journal to users. Along the path, we realized that the Account model was missing, so I stopped to build that out before we could proceed. By the end of the stream, we had a working background job that would send email and was 100% unit tested. -
Accounts and Email - Building SaaS with Python and Django #164
In this episode, I planned to do the work of sending email prompts for the journal to users. Along the path, we realized that the Account model was missing, so I stopped to build that out before we could proceed. By the end of the stream, we had a working background job that would send email and was 100% unit tested. -
Two Ways to Turbo-Charge tox
No, it’s not (just) run-parallel – let’s cut the local tox runtime by 75%! -
Django News - Bringing Locality of Behavior to Django - Jun 23rd 2023
News The 2023 PSF Board Election is Open! In order to vote in this election, individuals must be a Contributing, Managing, Supporting, or Fellow member as of June 15, 2023, and have confirmed their intention to vote by June 19, 2023. blogspot.com Wagtail 5.0.2 release notes New features and bug fixes in the latest Wagtail version. wagtail.org Announcing Our New Security Developer in Residence! The Python Software Foundation now has a security developer in residence. blogspot.com Updates to Django Updates to Django From Django Review and Triage Team Member Sarah Boyce... Last week we had 13 pull requests merged into Django by 10 different contributors - including 2 first time contributors! Congratulations to Olivier Le Thanh Duong and Ashwin Dharne for having their first commits merged into Django - welcome on board! This time filtering support was added to GIS aggregate functions, and an offset value was added to StepValueValidator! You will be able to use both of these features in 5.0. Do you want to add something into Django 5.0? Why don't you update assertContains and assertInHTML to output a haystack on failure #34657? Look forward to welcoming you on board! github.com Sponsored Link Learn More About our Django …