Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Sync or Async? Unpacking the Mysteries of Django Signals
Django is a popular web framework for Python developers, known for its robustness, flexibility, and security. One of the features that make Django powerful is its signal system. Signals allow developers to trigger certain actions when specific events occur, such as when a model is saved or deleted. However, there is often confusion about whether Django signals are asynchronous or not. In this article, we will explore this question and discuss the tradeoffs associated with using Django signals. -
Time Travel with django-simple-history
If you’re interested in Django development, you might have come across the django-simple-history package. It’s a great tool that can help you keep track of changes made to your models over time. In this article, we’ll take a closer look at django-simple-history and how it can benefit your projects. What is django-simple-history? django-simple-history is a third-party Django package that provides version control for your models. It allows you to keep track of changes made to your models, including who made the change, when it was made, and what the change was. -
Learn Django or Ruby on Rails?
I got a question from a patron on Patreon. The question is a common one, so I thought I’d share it along with my response. Was there a reason why you picked the Django for your web development? Did you consider RoR? Does it matter which stack I use at the end of the day? My primary reason for getting into Django was twofold. First, I’ve been working with Python for a long time and have a lot of comfort with the language. -
Django News - Django Developers Survey 2022 Results - Mar 10th 2023
News Django Developers Survey 2022 Results The results of the 2022 Django Developers Survey are now live. Almost 5,000 Django users from 248 countries took the survey. djangoproject.com Python Insider: Python 3.12.0 alpha 6 released Python 3.12.0a6 is the sixth of seven planned alpha releases. Alpha releases are intended to make testing the current state of new features and bug fixes easier. Today is a good time to start testing your code with Python 3.12. blogspot.com Sponsored Link Get Expert Developer Support from the creators of Wagtail CMS Get support for your developers from our team of Wagtail experts: from reviewing your Wagtail set-up and planning complex features, to code reviews, pair programming and more. We offer a range of plans, special pricing for charities and universities, and profits are invested in Wagtail product development. bit.ly Articles Django: How to profile and improve startup time A post on several tools for profiling startup time and tactics for reducing it. adamj.eu More Batteries Please Django Fellow Carlton Gibson with some thoughts on how/why to bring more official batteries into Python. noumenal.es Testing multiple Python versions with nox and pyenv If you need to test your code against multiple versions of Python … -
Weeknotes (2023 week 10)
Weeknotes (2023 week 10) FeinCMS bugs FeinCMS is really stable (since there isn’t much going on) but this week a Django upgrade surfaced bugs in the datepublisher extension. The extension uses a granular_now utility to determine if a page should be shown or not; the time is rounded to a 5-minute boundary which makes some sorts of caching more effective. On one hand it’s a bit sad that activity on the project has practically ground to a halt, on the other hand it’s great that the project requires practically no changes when a new version of Django is released. Stability is awesome. 15 years of using GitHub I used Subversion and darcs for probably not much more than a year each before discovering Git probably some time in spring 2006. It was a very archaic version with a much worse CLI than today. Everything was archaic, not just the CLI itself but also the repository browsers and the various web UIs. But everything was also very interesting to me. I especially found the emphasis on clean data structures instead of code very inspiring. And here we are, basically all the tools have been rewritten but the commits from back then … -
Go live checklist for your Django project
Launching a website can be an exciting but nerve-wracking experience. With so many moving parts in the website development process, it’s easy to overlook small details that can significantly impact the user experience. To help you avoid potential issues, we’ve compiled a checklist of things to verify before your site goes live. Here it is an opinionated production checklist that is tailored to a high-traffic website (100k Requests per day and above). Django settings Django DEBUG = False Django SESSION_ENGINE = django.contrib.sessions.backends.cached_db or django.contrib.sessions.backends.signed_cookies Django ALLOWED_HOSTS is set to match your domain Django CACHES should use either memcached or redis backend Verify Django the value of settings.DEFAULT_FROM_EMAIL Static files are not served by Django Server configuration & checks Confirm that you have multiple instances of your web application. Verify the output of manage.py check --deploy directly on the production server Error and exception are logged into SENTRY UWSGI Harakiri timeout --harakiri=10 Check that logger.error(…) and logger.info(…) is sent to your logging pipeline Verify that your production dashboard has information about Load and balancer request per minute 2XX, 3XX, 4XX, 5XX AVG and p99 response time for your web application database CPU load and transaction per minute Confirm that you have … -
Django News - DjangoCon US 2023 CFP is open - Mar 3rd 2023
News DjangoCon US 2023 Call for Proposals (CFP) is open! Submit your proposal by May 15, 2023 and encourage your friends and colleagues to do the same. djangocon.us Sponsored Link Register for Python Web Conf Today! Join Djangonauts from around the world for the 5th annual Python Web Conference (March 13-17). Tickets include 5 days, 65+ live talks, expert-led tutorials, social events, an exclusive pass to all conference recordings for 90 days, cool swag and more. Don’t wait, buy your ticket today! pythonwebconf.com Articles Formatting Gone Wrong Using black to format your Python code is usually a good idea but can sometimes cause unexpected errors. A case study on when this happens in Django around API keys. revsys.com Python is two languages now, and that's actually great A look at how both untyped and typed Python are used these days. threeofwands.com Single host Django and Docker deployment A good starting point for a "minimum viable deployment strategy" with new Django projects. screamingatmyscreen.com Using pyproject.toml in your (Django) project How and why to use pyproject.toml in your Django projects instead of older options like setup.py. lincolnloop.com Django: How to profile and improve startup time Adam Johnson shows us to profile and … -
Weeknotes (2023 week 8 and 9)
Weeknotes (2023 week 8 and 9) Last week was a short work week. We spent a few nights in the mountains. Not much snow though. Enough for some skiing and sledging. This work week was … not normal. Many meetings, not enough time to work on projects. That shortens these week notes a lot. Django Software Foundation membership I found out through Tim that I have been approved as an individual member of the Django Software Foundation. I’m honored and hope that this will be another way where I can give something back. It also feels good to be seen. I didn’t even know that the Foundation’s meeting minutes were public. I still use RSS and can wholeheartedly recommend The Old Reader (no affiliation) and so I thought I’d try adding a RSS feed of meeting minutes to the website. The pull request is still being reviewed. at the time of writing. feincms3-forms documentation I worked on the feincms3-forms README a bit. The README hopefully clarifies the purpose and the components of the app a bit. This is an extremely flexible forms builder for the Django admin interface. Migrating from Bitbucket to GitHub I have been a long time Bitbucket … -
Django: How to profile and improve startup time
Your Django project’s startup time impacts how smooth it is to work with. Django has to restart your project every time you run a management command and when runserver reloads. This involves importing all your apps, and thus all the modules that they import. As you add more code and dependencies to your project, you may notice its startup time increasing. Development can slow down to a crawl; reports of 10 second startup times are, sadly, not unusual. In this post we’ll cover tools for profiling startup time, and tactics for reducing it. How to profile startup time Here are several tools for profiling startup time. -X importtime: Python’s import profiler Python 3.7 introduced the -X importtime option, a specialized profiler that times all imports. It prints a table to stderr, summarizing microsecond timing information for each imported module: $ python -X importtime -c 'import django' import time: self [us] | cumulative | imported package import time: 136 | 136 | _io import time: 20 | 20 | marshal import time: 256 | 256 | posix import time: 261 | 672 | _frozen_importlib_external ... import time: 499 | 6898 | subprocess import time: 309 | 309 | weakref import time: … -
Inventory Management / Custom 404 page / Go gqlgen - Building SaaS #154
In this episode, I did another Exercism problem in Python which focused on working with dictionaries. Once the exercise was complete, we worked on the homeschool app and created a custom 404 page so that Django would render something beyond a plain page. After working on Django, I did something totally different and worked on some Go code and used gqlgen to create a GraphQL service with generated code produced via a GraphQL schema. -
Inventory Management / Custom 404 page / Go gqlgen - Building SaaS #154
In this episode, I did another Exercism problem in Python which focused on working with dictionaries. Once the exercise was complete, we worked on the homeschool app and created a custom 404 page so that Django would render something beyond a plain page. After working on Django, I did something totally different and worked on some Go code and used gqlgen to create a GraphQL service with generated code produced via a GraphQL schema. -
Dev Environments - Calvin Hendryx-Parker
Python Web Conference 2023 - early bird tickets get 15% off with sponsor code DjangoChat@PWC2023Calvin Hendryx-Parker on GitHubSix Feet UpApache Airflow and DAGsToo Big for DAG Factories?Choose Boring TechnologyskaffoldPyCon US 2022 Talk: Bootstrapping Your Local Python EnvironmentPyCon Italia 2023How to Install Django Support 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. -
Deploying a Django App to Azure App Service
This tutorial looks at how to deploy a Django application to Azure App Service. -
Single host Django and Docker deployment
One of the best ways to deploy a Django project while maintaining some sanity is Docker. A single, beefy VM or bare metal host will likely bring you a long way when just starting a new project or while working on a side project that does not have to scale to infinity and beyond. Usually you build a Docker image, upload it to a container registry and deploy from the registry. This results in a few more moving parts than I am okay with for a quick side project or something small (like this blog). For this to work you either run a container registry yourself, or trust a third party with keeping your images secure and private. One requires trust in third parties, the other means more work and time for something you can spend on more fun things like your actual project. So let us skip this step. I am using this blog as an example. In the spirit of staying true to "tech quips" I will use an early, working iteration of the deployment script. I will add some notes at the bottom what you should consider doing and what I already changed. The Dockerfile itself is … -
Django News - Django 4.2 beta 1 released - Feb 24th 2023
News Django 4.2 beta 1 released Django 4.2 beta 1 is now available. It represents the second stage in the 4.2 release cycle and is an opportunity for you to try out the changes coming in Django 4.2. djangoproject.com Google Summer of Code: Django 2023 Django was once again selected for Google's Summer of Code this year. This program has directly led to real improvements in frameworks over the year. You can learn more about mentorship and applying (applications open until April 4) on the Django website. withgoogle.com Django Software Foundation DSF Board monthly meeting, February 8, 2023 Did you know the DSF Board minutes are public and hosted every month? Take a look to see what the Board is workingon. djangoproject.com Sponsored Link Register for Python Web Conf Today! Join Djangonauts from around the world for the 5th annual Python Web Conference (March 13-17). Tickets include 5 days, 65+ live talks, expert-led tutorials, social events, an exclusive pass to all conference recordings for 90 days, cool swag and more. Don’t wait, buy your ticket today! pythonwebconf.com Articles Hypermedia Systems Hypermedia Systems is an in-progress book that employs a more straightforward approach to building applications on the Web and beyond … -
How to migrate from Django’s PostgreSQL CI Fields to use a case-insensitive collation
If you upgrade to Django 4.2, you may see system check warnings like: example.User.email: (fields.W906) django.contrib.postgres.fields.CIEmailField is deprecated. Support for it (except in historical migrations) will be removed in Django 5.1. HINT: Use EmailField(db_collation="…") with a case-insensitive non-deterministic collation instead. In this post we’ll cover why this has changed, and how to perform the necessary migration. You can actually migrate from Django 3.2, and may want to, because the alternative uses more accurate and flexible Unicode rules. What changed, why As covered in the miscellaneous release notes, three field classes and a mixin are deprecated: CICharField CIEmailField CITextField CIText mixin The CI* fields provide Case-Insensitive versions of their vanilla counterparts. These use the citext module built-in to PostgreSQL. But, since version 12, PostgreSQL discourages using citext, stating: Consider using nondeterministic collations instead of this module. They can be used for case-insensitive comparisons, accent-insensitive comparisons, and other combinations, and they handle more Unicode special cases correctly. Essentially, collations are more featureful and correct. The deprecation in Django 4.2 encourages you to follow PostgreSQL’s advice. You can specify a collation for CharField, TextField, and subclasses like EmailField, with the db_collation argument (added in Django 3.2). So for case-insensitive fields in PostgreSQL, you … -
Developing an API with FastAPI and GraphQL
In this tutorial, you'll learn how to build a CRUD app with FastAPI and GraphQL. -
Review: Django Essentials
A month ago Dyson D'Souza from PacktPub approached me asking if I would be interested in reviewing Django Essentials. I am using Django for some time now - somewhen pre 0.96, I remember the 0.96 release for some reason, I think it was the length of the release cycle but I am not sure anymore - and I really wanted to see how the introduction resources changed, so this was a good chance. Samuel Dauzon does a really good job writing for people who are just starting to work with Django. Beside some history he manages to explain all important concepts and, this is something I especially like, transports them to the terminology used by Django. After explaining what MVC is he also explains what Django is calling the different parts and how they fit together. This is something I often missed when reading a blog post or skimming through another book. While it is a good introduction you should already now a little bit of Python to feel comfortable. The book is suggesting Python 3 which is in my opinion still a risky route to take for a beginner. While most libraries are ported you can still easily run … -
Django & Rails - another year another comparison
It is the time of the year where I start talking about Django and Ruby on Rails. Since my last two posts I received many questions about this topic and the old posts are still read frequently and quoted. So let me bring you up to date what changed, what improved since the last post and which framework is the best choice. If you did not read my last two posts about this topic I suggest you read them now. I will make claims and statements in this post I already elaborated in them and without the context they can be quite controversial. To the disappointment of some of you: this is still not Django vs Rails - it is no discussion that will come to the conclusion that there is a holy grail of frameworks, totally destroying one of them with arguments why the other one is so superior. While Django is slowly moving towards migrations being part of the core functionality Ruby on Rails just added support for real foreign keys support. Django 1.7, which will bring you the joy of migrations, is currently not marked as stable, but release candidate two makes a good impression and it … -
Upgrading Django Projects - Introduction
One questions I am asked quite often is how to upgrade larger projects to a newer Django release. While upgrading to a newer minor release is usually really easy and does not require much work it can become a bit harder upgrading to a new major release. My oldest project points back to 0.9x, so it has seen some upgrades, and there are certain patters that proved to work pretty well. Upgrading a Django project is not harder or easier than upgrading any other project of the same size which is using a big third party framework as base and smaller libraries for certain parts of the system. I will try to start with general and simple principles on upgrading projects and move to more Python and Django specific topics later on. Before upgrading you should ask yourself if you have to. Let us assume your application is running fine and you are on a release that still gets bugfix and security updates. You could upgrade to get new features that eventually help you down the road. Or you could implement a new feature that separates your application from all competitors. The answer in that case is pretty obvious, isn’t … -
Individual member of the Django Software Foundation
Last Saturday, somewhen late at night when we came back home from our trip to the city, I received an unexpected mail. I was nominated, seconded and approved to be an Individual Member of the Django Software Foundation. This came completely unexpected and honestly caught me a bit off guard. I let it sink in a bit and accepted the invitation on Sunday, with a nice glass of scotch next to me. I have been using Django since 0.96-svn or so and I have been using it to ship production software for a decade. (Yes, I was actually crazy enough to bet on a pre 1.0 release framework instead of TurboGears which was a bit more established, had a nicer ORM and some really nice JavaScript integration.) During all those years I experienced a warm, welcoming and inclusive community that is also able to talk tech. This is a very nice combination. I have seen communities which are also welcoming and inclusive but lacked the technical capabilities to drive a project forward. And I have seen technical capable communities I would not want to spent five minutes with in a room full of liquor. Django was and still is the … -
Managing state in Django models
A Django model often will contain some form of state. And there will most likely be events which modify the state. While those two things are not always called like this, the concept still exists. More often than not you will find a view controller assigning the new state to an instance of a model when certain conditions are met. In some cases you will see the event code being abstracted to make it easier to test, maybe in a separate function or class, maybe to a model method. And more often than you should you will see this messing up the state of an instance forcing someone to wake up at 2am to connect to the database - or Django admin if setup - and set a valid state. Thankfully the chance for the last thing to happen can be greatly reduced. Over the years I found that not everyone is familiar with the concept of a finite-state machine (which would help addressing this problem). I have also met people who had in depth knowledge of state machines in all their forms and would have been able to implement one as a stand-alone system, but had trouble integrating one … -
Adding two factor authentication to Django admin
As my dissatisfaction with WordPress grew, I did the only Reasonable Thing(tm) and decided to roll out my own CMS again. Which means I do not only have the joy of building a tool exactly fitting my needs, but I also have to build some of the functionality I would expect every production-ready system to provide. Account security in Django's contrib.auth and contrib.admin package did not change a lot over the last decade, but in 2020 I expect some basic functionality from every system, like two factor authentication. As 2FA is missing in Djangos admin package, what is the Reasonable Decision(tm)? To add it myself, of course. You might see a trend of "reasonable yak shaving" here. (A small side note if you are working on a SaaS or web app right now: Account security is not a "premium feature" or a feature your users should have to pay for. It is basic functionality you should always provide to anyone, no matter if they are free or paid users, no matter which plan. And now back to our scheduled program!) This article assumes you have some familiarity with Python and Django; at least enough to create a new application, inherit … -
Thoughts on „Surviving Django“
Daniele, the author of psycopg2, wrote an interesting post about Django and its migration system. Having used Django for well over a decade and having worked on projects either handed to me or greenfield at different scales I cannot agree with his arguments as they are stated. The migration and ORM system does solve a far larger problem than allowing web apps to switch between databases. Djangos migration system is primarily a developer tool. A rather excellent one I cannot praise enough. It abstracts and standardises the way database migrations are handled. Remember following a document outlining the order of 15 migrations to apply when doing a deploy? Remember trying to add a 16th? I surely prefer running makemigrations. Is it perfect? No. Can a talented DBA get far more out of a database? Absolutely. Is any of that more relevant than safeguards and ease of use for 90% of the apps out there? Definitely not. Now to the really good part - you can have the best of both worlds! Migrations can run Python and SQL, while still giving you some of the safeguards and making it comfortable to use. They will not get in your way, but spare … -
Deep dive: Django Q and SQS
When working on a Django application the de facto recommendation for a task queue is Celery. I believe this is a good recommendation. It is kind of like buying IBM - “no one was ever fired for buying IBM”. I started using Django Q more recently and it is doing a great job. One system I built using it processes roughly 400k tasks per day. Surely not the largest system and surely not the most impressive number, but decent enough to say that Django Q is a solid choice. But as with many smaller projects there are sometimes a few gotchas you are running into. This becomes painfully obvious when setting up an app using SQS. Let me walk you through the steps I took to make Django Q play nicely with our AWS setup at Grove Collaborative. Redis is great, but… First of all you have to configure Django Q to use SQS. You do this by adding the Q_CLUSTER dictionary to your settings.py with the sqs key. If you are familiar with AWS and boto3 you might know that you can either provide the AWS region when initialising a new connection or you can have a standard config …