Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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 … -
First Major Model - Building SaaS #163
In this episode, we got to work on the core modeling for the application. I started by adding some visualization tooling to see the models in the system, then got to modeling of the primary Entry model that will be used throughout the app. Along the way, we set up the Django admin and did some automated testing. -
First Major Model - Building SaaS with Python and Django #163
In this episode, we got to work on the core modeling for the application. I started by adding some visualization tooling to see the models in the system, then got to modeling of the primary Entry model that will be used throughout the app. Along the way, we set up the Django admin and did some automated testing. -
How to Learn Django (Replay)
Learning Python via Django Considered HarmfulDjango Girls TutorialDjango for BeginnersInstall Python3 on Mac/Windows/Linuxawesome-django repodjango-vanilla-viewsClassy Class-Based Views siteDjango Deployment ChecklistGroupsDjango Users Google GroupStack OverflowSubreddits: LearningDjango and DjangoDjango MeetupsSHAMELESS PLUGSLearnDjango.comCarlton's website Noumenal -
2023 Python Software Foundation Board Nomination
My self-nomination statement for the 2023 Python Software Foundation (PSF) Board Election -
2023 Python Software Foundation Board Nomination
My self-nomination statement for the 2023 Python Software Foundation (PSF) Board Election -
Python Community News Interview
Interview I gave to the “Python Community News” channel regarding my self-nomination for the 2023 Python Software Foundation (PSF) Board of Directors elections. -
FeinCMS is a dead end (but feincms3 is not)
FeinCMS is a dead end (but feincms3 is not) I wouldn’t encourage people to start new sites with FeinCMS. Five years ago I wrote that FeinCMS is used in a few flagship projects which we’re still actively developing, which means that FeinCMS won’t be going away for years to come. That’s still true but less and less so. We’re actively moving away from FeinCMS where we can, mostly towards feincms3 and django-content-editor. FeinCMS lives on in django-content-editor and feincms3; not only in spirit but also in (code) history, since django-content-editor contains the whole history of FeinCMS up to and including the beginning of 2016. The implementation of FeinCMS is too expensive to clean up without breaking backwards compatibility. I still wish I had pursued an incremental way back then which would have allowed us to evolve old projects to the current best way of doing things (tm), but it didn’t happen and I’m not shedding too many tears about that since I’m quite happy with where we’re at today. That basically means that I won’t put any effort into bringing FeinCMS and django-content-editor closer together. I haven’t spent much time on that anyway but now my mind is made up … -
Streaming Protocols continued... RTMP, MMS
Audio streaming protocols explained with rtmp and mms in depth. We develop audio streaming services and we will setup your internet radio. -
Django - Database access optimization
Django - Database access optimization. Write the best query to reduce the time and improve the application performance. using select_related and prefetch_related will form sql query with joins. In some cases It will reduce extra queries to the database. -
What's great about Django girls to inspire women into programming
Django girls is a non-profit organization, that helps women to learn Django programming language and to inspire them into programming. -
Python development environment on windows
Python development environment on windows in an easy and simple way -
Streaming protocols ogg, mp3, aac
Audio streaming protocols ogg, mp3 and aac explained in simple and advanced methods. We develop internet radio stations and we can do it for you.