Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django: Maybe disable PostgreSQL’s JIT to speed up many-joined queries
Here’s a write-up of an optimization I made in my client Silvr’s project. I ended up disabling a PostgreSQL feature called the JIT (Just-In-Time) compiler which was taking a long time for little benefit. This behaviour was observed on PostgreSQL 14, so things may have improved since. Although the version 15 and 16 release notes don’t seem to contain any relevant-looking changes. Okay, story time… I was looking at the project’s slowest tests and found one that took five seconds despite containing few lines of code. Profiling the test revealed a single slow query, which was also slow in production. I grabbed the query plan and fed it to pgMustard using the technique I previously blogged about): pgMustard reported that JIT compilation of the query was taking 99.7% of the 3217ms runtime. The five-star rating for this finding meant that it was ripe for optimization. But why was JIT compilation taking so long? The query used InheritanceManager from django-model-utils, which extends Django’s multi-table inheritance to return heterogenous subclasses of a base model: >>> Place.objects.select_subclasses() [<Library: Downtown Books>, <BookShop: Giovanni’s>] The generated query joins all subclasses’ tables. With many subclasses, that query has many joins. But each join only adds a … -
Contributing to Django - Sarah Boyce
Sarah Boyce on GitHub Django Triage & Review TeamDjangonaut.Space PyDev of the Week: Sarah Boyce Django Discord Channel Support the ShowLearnDjango.comButtonDjango News newsletter -
Database generated columns ⁽¹⁾: Django & SQLite
An introduction to database generated columns, using SQLite and the new GeneratedField added in Django 5.0. -
How to Kill the Django Development Server Without Ctrl+C
Let's say you're developing a Django project and you've lost track of the terminal window that ran your python manage.py runserver command. If you can't press Ctrl+C in the terminal, how do you stop the server? Finding the runserver Process First, we need to find the ID of the manage.py runserver process. On Linux, you can list all processes with the following command: ps aux To search the results, you can pipe the output of that command into the grep command: ps aux | grep manage.py If you want to search multiple words, enclose them in single quotes ' or double quotes ": ps aux | grep 'manage.py runserver' This should give you rows of table data such as: lance 12839 0.0 0.1 57068 49840 pts/25 S+ 07:11 0:00 python manage.py runserver lance 12840 23.0 0.2 435156 67752 pts/25 Sl+ 07:11 4:40 /home/lance/django-workout/.venv/bin/python manage.py runserver lance 23752 0.0 0.0 4040 1980 pts/30 S+ 07:31 0:00 grep --color=auto manage.py runserver This can be confusing because there are a few numbers here and I'm not sure what each number represents. To prepend a row of headers, we can run two commands back-to-back: ps aux | head --lines=1 && ps aux | grep … -
Adding Full Text Search to Your Django App with django-watson
Learn how to supercharge your Django app with full-text search using Django-Watson. Dive deep into Postgres magic and boost search functionality. -
Django News - 204 No Content - Django 4.2.7, 4.1.13, and 3.2.23 Security Release - Nov 3rd 2023
News Django security releases issued: 4.2.7, 4.1.13, and 3.2.23 A new security release for a potential denial of service vulnerability in UsernameField on Windows. As ever, the best security practice is to keep your Django version up to date with the latest release. djangoproject.com Python Software Foundation News: Announcing our new Community Communications Manager! The PSF's first Communications Manager will establish a PSF communications calendar, including annual messaging, newsletters, and blog posts. She will also partner with our Executive Director, Deb Nicholson, and other staffers to enhance our support for the Python community with various initiatives. blogspot.com Updates to Django Last week we had another massive 18 pull requests merged into Django by 13 different contributors - including 4 first time contributors! Congratulations to ksg, Leo Suarez, Izzy Hyman and CheesyPhoenix for having their first commit merged into Django - welcome on board! The System check framework docs now has a new section on writing integration tests: System check framework - Writing integration tests. I always love to see the documentation continue to improve to better serve the community! Coming in Django 5.1, there will be a new template tag {% query_string %} that allows changing a django.http.QueryDict instance for … -
Weeknotes (2023 week 44)
Weeknotes (2023 week 44)Unmaintained but maintained packages There’s a discussion going on in the django-mptt issue tracker about the maintenance state of django-mptt. I have marked the project as unmaintained in March 2021 and haven’t regretted this decision at all. I haven’t had to fix inconsistencies in the tree structure once since switching to django-tree-queries. And if that wasn’t enough, I get little but only warm and thankful feedback for the latter, so that’s extra nice. Despite marking django-mptt as unmaintained I seem to be doing a little bit of maintenance still. I’m still using it in old paid projects and so the things I do to make the package work for me is paid work. I’m not personally invested in the package anymore, so I’m able to tell people that there are absolutely no guarantees about the maintenance, and that feels good. Read the Docs I do understand why the .readthedocs.yaml file is now necessary. I wish that I wouldn’t have to do all the busywork of adding one to projects. I have just resubscribed to the Read the Docs Gold Membership which probably has expired at some point in the past. Read the Docs is excellent and everybody … -
Introducing djarter – An opinionated Django starter project
I have spent six years resisting the urge to make a starter template because (a) it locks you in to a particular development style, and (b) it prevents the repetition that promotes learning. But in the spirit of deploying high quality work, this repo contains a few best practices and useful tools for Django projects. These features would take a while to get set up from scratch, and might not be worth it for every project. But cloning this starter template can save you roughly a full day of work if you're planning to extend the built-in user authentication. Most importantly, though, no Bootstrap styling was used in the making of this template. Check out djarter on GitHub. -
Idempotent Jobs - Building SaaS #174
In this episode, we cleaned up the email sending job. I had to make some changes based on some discoveries that I made while researching how to track responses and associate the journal entries back to the user. While doing this clean up, we added a new Prompt model to make the email sending job idempotent for each day. -
Idempotent Jobs - Building SaaS with Python and Django #174
In this episode, we cleaned up the email sending job. I had to make some changes based on some discoveries that I made while researching how to track responses and associate the journal entries back to the user. While doing this clean up, we added a new Prompt model to make the email sending job idempotent for each day. -
Guide to setting up GeoDjango on Mac M1
There are a lot of guides on setting up GeoDjango and PostGIS. But most of them are outdated and doesn't work on Mac M1. In this article, let us look at how to set up GeoDjango on Mac M1/M2. Ensure you have already installed Postgres on your Mac. Install GeoDjango The default GDAL version available on brew fails to install on Mac M1. $ brew install gdal ==> cmake --build build Last 15 lines from /Users/chillaranand/Library/Logs/Homebrew/gdal/02.cmake: [javac] Compiling 82 source files to /tmp/gdal-20231029-31808-1wl9085/gdal-3.7.2/build/swig/java/build/classes [javac] warning: [options] bootstrap class path not set in conjunction with -source 7 [javac] error: Source option 7 is no longer supported. Use 8 or later. [javac] error: Target option 7 is no longer supported. Use 8 or later. BUILD FAILED /tmp/gdal-20231029-31808-1wl9085/gdal-3.7.2/swig/java/build.xml:25: Compile failed; see the compiler error output for details. Total time: 0 seconds gmake[2]: *** [swig/java/CMakeFiles/java_binding.dir/build.make:108: swig/java/gdal.jar] Error 1 gmake[2]: Leaving directory '/private/tmp/gdal-20231029-31808-1wl9085/gdal-3.7.2/build' gmake[1]: *** [CMakeFiles/Makefile2:9108: swig/java/CMakeFiles/java_binding.dir/all] Error 2 gmake[1]: Leaving directory '/private/tmp/gdal-20231029-31808-1wl9085/gdal-3.7.2/build' gmake: *** [Makefile:139: all] Error 2 We can use conda to install gdal. Create a new environment and install gdal in it. $ conda create -n geodjango python=3.9 $ conda install -c conda-forge gdal $ pip install django $ pip install psycopg2-binary … -
Django News - Django 5.0 beta 1 released and Django News Jobs - Oct 27th 2023
News Django 5.0 beta 1 released Django 5.0 beta 1 is now available. It represents the second stage in the 5.0 release cycle and is an opportunity for you to try out the changes coming in Django 5.0. djangoproject.com The Ruff Formatter: An extremely fast, Black-compatible Python formatter Ruff added a Black linter/formatter that is over 30x faster than existing tools while maintaining >99.9% compatibility with Black. If you haven't used Ruff before and are tired of waiting on your linting/formatting tools to run, now is a good time. astral.sh Updates to Django Last week we had a massive 16 pull requests merged into Django by 12 different contributors (you can tell there was a sprint) - including 5 first time contributors! Congratulations to Claire Pritchard, Lance Goyke, Chris Frisina, laserhyena and ontowhee for having their first commit merged into Django - welcome on board! This week there was a flurry of accessibility fixes around the Django admin. Including correcting the main content element (#34905), correcting HTML heading levels (#34911), fixing the size of back links (#34912), and adding borders in high contrast mode (#34913). We also added screenshot taking to Django's internal selenium test suite so that we can … -
μDjango (micro Django) 🧬
A single file Django micro project created for demonstration purposes to be used in the same way as other Python frameworks. -
Becoming a Django Fellow - Natalia Bidart
Djangonaut Space - 2024 Session 1 ApplicationWelcome our new Fellow - Natalia BidartEiffelDjango security releases issued: 4.2.6, 4.1.12, and 3.2.22 Django 5.0 Alpha Release NotesSupport the ShowLearnDjango.comButtonDjango News newsletter -
How to import requirements.txt into Poetry
First of all, congratulations on choosing Poetry for your Python project management. It’s a fantastic choice, and I hope that Poetry becomes the de facto standard. It’s time to bid farewell to the good old, barebones requirements.txt file, to move your dependencies over to Poetry, and let it handle everything—including … Read now -
Django News - 202 Accepted - Django, Django, Django - Oct 20th 2023
Django Software Foundation Announcing DSF Working Groups Previously, you more or less needed to be a board member to help; now, anyone can join — or form — a working group to further the DSF’s mission. djangoproject.com 2024 DSF Board Nominations Nominations are open for the 2024 Django Software Foundation Board of Directors. Anyone can apply. djangoproject.com Djangonaut Space now accepting applications for our next contributor mentorship cohort Apply for an 8-week group mentoring program where individuals will work self-paced in a semi-structured learning environment to contribute to Django. The deadline to apply is November 15th, 2023. djangoproject.com Nominations for 2023 Malcolm Tredinnick Memorial Prize An annual monetary prize awarded to the person who best exemplifies the spirit of Malcolm’s work in the Django community. djangoproject.com Updates to Django Last week we had 9 pull requests merged into Django by 6 different contributors - including 1 first time contributor! Congratulations to lufafajoshua for having their first commit merged into Django - welcome on board! This week mostly featured a number of small documentation and test improvements. Though a 14 year old bug also got closed! Previously a query string (which is used to pre-fill the form) would be lost when … -
Customize the Django admin to differentiate environments
Customize the Django admin to differentiate environments We often have the same website running in different configurations: Once as a production site. Once as a place where editors update and preview the content. The content is later automatically (and maybe partially) transferred from this environment to the production environment. Once as a stage environment to stabilize the code. And maybe additional environments for local development. The Django admin panel mainly uses CSS variables for styling since theming support was introduced in Django 3.2 (by yours truly with a lot of help from others). This makes it simple and fun to customize the colors of all interface elements in a straightforward way without having to write loads of CSS. If you have a ENVIRONMENT context variable available (as we do) you could add the following template as admin/base.html to your project, giving you a red color scheme for the production environment (to discourage people from updating content) and a nice scheme for the preproduction environment which clearly deviates from the standard color scheme used everywhere else: {% block extrahead %} {{ block.super }} <style> #site-name::after { content: " ({{ ENVIRONMENT }})"; font-size: 60%; } </style> {% if ENVIRONMENT == 'production' %} … -
Email Round Trip - Building SaaS #173
In this episode, we took advantage of having all the DNS configuration complete and tried to find the path to connect the outgoing prompt email to the incoming journal entry from a user. We did this with some old-school print debugging and logging on production to see exactly what data is provided to the receiver webhook. -
Email Round Trip - Building SaaS with Python and Django #173
In this episode, we took advantage of having all the DNS configuration complete and tried to find the path to connect the outgoing prompt email to the incoming journal entry from a user. We did this with some old-school print debugging and logging on production to see exactly what data is provided to the receiver webhook. -
Weeknotes (2023 week 42)
Weeknotes (2023 week 42)Vacation in Italy We have spent a wonderful family week in Italy. The voyage by train was very comfortable and we had a great time there. I have lived close to lakes all my life but the sea is always something else. Now I enjoy the cold temperatures of fall. Going back (forward) to GitJournal I have tried several note taking apps but I’m now back using GitJournal with a Git repository filled with Markdown notes. It works well enough. I just wish that there was a way to make notes more distinguishable and I wish that the editor was more forgiving when encountering badly formatted checklists. Analog blogging I have long wanted to write about our switch from Slack to Discord. I have started to write this post with pen and paper. I find that I think better when using pen and paper than when using the computer keyboard. One factor is certainly that the computer offers more distractions, but I suspect that another, more important factor is that as a fast typist the fingers and the thinking are always getting out of step, and this happens less when using a slower method of writing. This … -
Boost Your DX bundle deal
I released Boost Your Git DX nearly two weeks ago. It’s the second in my “Boost Your DX” series, following last year’s Boost Your Django DX. Both books aim to improve your development experience with their respective tool. Today I’m happy to announce the bundle deal for the pair of books. Check out either of the two books, enter your details and click “pay”, and you’ll be offered a $10 discount on the second one: If both topics interest you, I hope this deal makes it worth your while to pick up the two books together. This offer does not apply to team licenses. And unfortunately, the discount doesn’t stack with the regional one for those in lower-income countries, due to a limitation on Gumroad. I hope they will add support in the future. Find the deal by going through the checkout process with either title: Boost Your Django DX Boost Your Git DX May you continually boost your developer experience, —Adam -
Django News - 201 Created - Last call for DjangoCon US 2023 tickets! - Oct 13th 2023
News Last call for DjangoCon US 2023 tickets! DjangoCon US kicks off this Monday, October 16th - 18th. Online tickets are still on sale! If you are attending this year, Jeff, Will, and Catherine will be there. Say hello in person or virtually. ti.to Help us make the djangoproject.com website better Did you know a redesign is happening to the main djangoproject.com website? Please fill out this concise survey to share your thoughts on improving it. google.com Updates to Django Last week we had 14 pull requests merged into Django by 10 different contributors - including 4 first time contributors! Congratulations to ume, Pieter Cardillo Kwok, Denis Rouzaud and Faishal manzar for having their first commits merged into Django - welcome on board! Features for Django 5.1 are already being accepted! 5.1 will allow template tags to set extra data for templates (#34883 and release note) and assertContains(), assertNotContains(), and assertInHTML() assertions will now add haystacks to assertion error messages (#34657 and release note). Next week is DjangoCon US! There are a number of ways you can engage in the conference virtually including get involved in the sprints! You can read about this on the Django forum and sign up. … -
Practical AI: HuggingFace Transformers and Diffusers for Beginners
This presentation provides a straightforward overview of the HuggingFace Transformers and Diffusers libraries. Aimed at those without a deep understanding of AI or ML, we’ll focus on practical, hands-on applications. We conclude by setting up a Flask app that generates AI images, demonstrating how these tools can be used to create useful applications. -
Practical AI: HuggingFace Transformers and Diffusers for Beginners
This presentation provides a straightforward overview of the HuggingFace Transformers and Diffusers libraries. Aimed at those without a deep understanding of AI or ML, we’ll focus on practical, hands-on applications. We conclude by setting up a Flask app that generates AI images, demonstrating how these tools can be used to create useful applications. -
The validation evolution: Pydantic V2tronger - Marcelo Trylesinski
(One of my summaries of the 2023 Dutch pythonconferentie python meeting in Utrecht, NL). Pydantic is a data validation library. It uses/extends python type hints to work during runtime instead of statically. Pydantic recently went from version 1 to 2. One of the changes was to split pydantic in a few packages. Pydantic core is now partially written in Rust! Some other changes: In Version 1 you could add a Config class inside your model class, but it was sensitive to spelling mistakes. Now they use a model_config attribute that prevents errors. As they were breaking the API anyway, they took the opportunity to change lots of names to make them clearer. @validator is now @field_validator which accepts extra attributes, for instance for doing a special check before or after the regular validation. "After" validations are handy as you can run a check after pydaantic has ensured it was the correct type, this prevents lots of error handling in your custom validation. BaseSettings is now in a separate python package as it got a bit too big. Several __something__ methods were changed to give you more options to change pydantic's behaviour. Some performance tips (see also https://docs.pydantic.dev/latest/concepts/performance/ ): Use model_validate_json() …