Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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 … -
Deploying Django at small scale
It feels like common knowledge and an accepted fact that you want to run PostgreSQL in production. And have some sort of load balancer to be able to scale your application server horizontally. Throw in Redis for caching and you have the most generic web application stack I can come up with. At scale this makes a ton of sense. It is a battle tested stack, that will most likely not fail you and if it does, there are tons of resources on how to fix it. Those are a lot of moving parts you want to keep updated and maintained, so let us talk about simplifying this stack a bit for small scale deployments. There are lots of resources out there explaining the setup I mentioned above. Those resources are valuable and will guide you through production setups you will see at many places. But what when you are just starting and want to get your first application online? Things can be a lot easier. I recently started moving my blog and photo sharing site to their own, small virtual server. I just blogged about the reason for doing this, so I will not go into detail. Both sites … -
Security 101: Securing file downloads
One of the most common way to handle user uploaded content is persisting the data to disk, or uploading it to an object store like AWS S3. Serving the content back to the user (or others) often is handled by returning the URL to the file. What is oftentimes missing is proper authentication and authorization, as engineers seem to believe no one will leak URLs, run enumeration attacks or simply try random strings. This is not just a data breach waiting to happen, it is one happening way too often. In this post we will look at three options how this can be solved. The examples which you can find in the demo repository are written in Python, using Django. All three should work just fine in basically any modern language and framework used for web development, and with most web servers and reverse proxies such as Nginx. I am using Caddy, as the configuration is concise and simple to follow. For all examples you can upload a file via Django Admin and browse and download the files by visiting /. All examples only check if the user is authenticated. In a real system you will most likely want to … -
Django News - Django security releases issued: 4.1.7, 4.0.10, and 3.2.18 - Feb 17th 2023
News Django security releases issued: 4.1.7, 4.0.10, and 3.2.18 This release fixes a potential denial-of-service vulnerability in file uploads. As always, updating to the latest version of Django is one of the best security measures you can take. djangoproject.com Release 2.0 · django-crispy-forms/django-crispy-forms PSA: django-crispy-forms 2.0 has been released and has a few major changes, which will require some extra time when you upgrade. Their guide can walk you through what is needed or you can pin to django-crispy-forms<2 for a while until you have time to migrate. github.com Dependency graph supports the Python PEP 621 standard | GitHub Changelog GitHub dependency graph now supports parsing Python dependencies for pyproject.toml files that follow the PEP 621 standard. github.blog Sponsored Link Apply Now: Backend Tech Lead for B2B SaaS Startup- Remote Available! Looking for an opportunity to build, lead, architect, and grow — both your career and a great product? Supplios builds supply-chain software for leading manufacturers and is looking for an experienced Python / Django developer to join the team in Copenhagen, Denmark or remote. supplios.com Articles Python/Django AsyncIO Tutorial with Examples An overview of asynchronous coding and how to apply it to Django. djangostars.com An introduction to Django Simple … -
Weeknotes (2023 week 7)
Weeknotes (2023 week 7) iOS and Kiosk mode I did some research on easy ways to put an iPad into Kiosk mode because I want to build a surveying app for an exposition. The web platform is perfect for this especially given the budget constraints… I thought What is iOS kiosk mode and how do I enable it? was a great overview over the available options for using iPads in Kiosk mode. I definitely don’t want to build an app myself even though this would be relatively straightforward e.g. with React Native1. The MDN Foxes example worked nicely apart from the fact that the bar containing the clock and indicators is still shown. This is probably an acceptable trade off, but we’ll see. Bitbucket to GitHub migration I have finally managed to bump against the GitHub API’s rate limit. I have transferred more than 300 private Git repositories from Bitbucket to GitHub. Most repositories aren’t used actively anymore, so it’s not really about GitHub vs. Bitbucket. The goal was simply to have one less tool to worry about. Downloading the list of all repositores in a workspace was surprisingly annoying and I spent too much time bumping my head against … -
django-upgrade release with Django 4.2 fixers
I just released django-upgrade 1.13.0. The headline features are some new fixers targetting Django 4.2, which is currently in alpha. Let’s walk through these new fixers. For more detail on any of them, see the Django 4.2 README section. New headers argument in tests Recent-ish Django versions have added easier mechanisms for reading and writing HTTP headers: Django 2.2 added request.headers. Django 3.2 added response.headers. One place that was still lacking was the test client, where you needed to set headers via their WSGI names: response = self.client.get("/", HTTP_ACCEPT="text/plain") In Ticket #34074 I proposed a new headers argument for the test client and request factory classes. David Wobrock picked up the ticket in October. After a few rounds of review from myself and others, it was merged in November. So from Django 4.2, you can use: self.client.get("/", headers={"accept": "text/plain"}) Much more consistent. After the PR was merged to Django, David got to work on a adding a corresponding fixer to django-upgrade. I just got around to reviewing, fixing, and merging the PR. Thanks David! So now django-upgrade can rewrite client calls using headers: -response = self.client.get("/", HTTP_ACCEPT="text/plain") +response = self.client.get("/", headers={"accept": "text/plain"}) …and instantiations of Client and RequestFactory: from django.test … -
Django 4.2 - Mariusz Felisiak
Mariusz Felisiak Mariusz on Mastodon Django 4.2 release notes - UNDER DEVELOPMENTStandout Features in Django 4.2 DSF calls for applicants for a Django FellowLearnDjango: How 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. -
Serving Static Files from Flask with WhiteNoise and Amazon CloudFront
This tutorial shows how to manage static files with Flask, WhiteNoise, and Amazon CloudFront.