Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
“Tell Me About a Project You Led…”
Part 2 of my Unpacking Interview Questions series, where I share one of the questions I use when I interview for technical roles. Today: measuring a manager’s ability to lead projects and manage them effectively. -
“Explain a Topic At Multiple Levels…”
Part 1 of my Unpacking Interview Questions series, where I share one of the questions I use when I interview for technical roles. Today: asking candidates to explain a topic at multiple levels. This is one of my favorite questions to ask for engineering roles; strong performance on this question correlates very highly with high job performance on my teams. -
How To Use Htmx In Django
This article show you how to use htmx in Django. What is htmx? According to the htmx website: htmx allows you to access AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext. The example that we’ll craft is an ability to delete a task from a list of tasks without reloading the whole page. -
New Committers for Tastypie & Haystack
New Committers for Tastypie & Haystack -
Django Dash - Registration Soon! (And Sponsors Needed)
Django Dash - Registration Soon! (And Sponsors Needed) -
The State of Tastypie
The State of Tastypie -
Django Dash & WSGI Wrestle Cancelled
Django Dash & WSGI Wrestle Cancelled -
Haystack & Tastypie Orgs
Haystack & Tastypie Orgs -
How to Deploy Django Channels 2.x on AWS Elastic Beanstalk (Amazon Linux 2)
Deploying Django Channels on Elastic Beanstalk is certainly a very arduous task. While there are certain resources available (in particular this medium post), they are still outdated and don't work directly on Amazon Linux 2. In this article, I'll w... -
Django News - Django 3.1.6 released - Feb 5th 2021
News Django security releases issued: 3.1.6, 3.0.12, and 2.2.18 These releases address a "low" severity issue but it is still highly recommended to upgrade your Django version as soon as possible. djangoproject.com You can now register for PyCon US 2021! PyCon US tickets are affordably priced for all levels from students to corporate ticket holders and financial aid is available. They have a special patron level for anyone who wants to see if their bosses are paying attention to their expense reports. blogspot.com Pip has dropped support for Python 2 The latest release (21.0.1) no longer supports Python 2. pypa.io Articles How to Limit Test Time in Django’s Test Framework Adam Johnson shows us how to implement a test time limit that automatically fails any long-running tests. adamj.eu Speed up pip downloads in Docker with BuildKit’s new caching Itamar Turner-Trauring shows us how to use Docker BuildKit's new caching to speed up pip install times. pythonspeed.com Docker, Django, Traefik , and IntercoolerJS as a SaaS Stack in 2021 A detailed look at one SaaS companies Django-based stack. simplecto.com Homebrew Python Is Not For You Justin Mayer makes a case for not depending on Homebrew Python. justinmayer.com Sponsored Link Build a … -
UX Polish - Building SaaS #90
In this episode, I worked on more customer requests to refine the user interface. We added a new convenient shortcut button and included additional information and links on the course detail view. I’m continuing on my path to include the changes that my customer wants as she running a school year for the first time. The first change was to add a new button on the student’s view of a course. -
Using Django Check Constraints to Limit A Model to a Single Instance
Yet another use case for creating a database constraint with Django’s CheckConstraint class. Sometimes it’s useful to have a model with only have one instance in the database, sometimes known as a singleton. This is useful for storing a small amount of structured data that we want to share between all our project’s processes. For example, imagine a remote API that we authenticate with using a temporary access token. We have the username and password for the API in our Django settings, and use those to get a temporary access token. We then need to store that temporary access token for all operations with that API, and refresh it when it nears its expiry time. And for security reasons, we are only allowed to store the current access token. We can store the token and its expiry in a model like this: from django.db import models class RemoteAPIAccount(models.Model): access_token = models.CharField(max_length=120) access_token_expires = models.DateTimeField() This model has the right fields for holding the token, but it can also have many instances of it in our database. We can write code that always uses a single instance by always the model through get_or_create() or update_or_create(), and passing all field values through … -
Wagtail, React, & Gatsby - Dawn Wages
Dawn’s personal siteDawn on Twitter @DawnWagesSaysWagtail Documentation SprintAt the Root: Wagtail + Gatsby + GitPod - PyConline AU 2020 talkWagtail CMSDecolonizing Technology on Martin Luther King Day 2021Biometric Insecurity - Carina C. Zona @PyConline AU 2020Support the ShowThis podcast is a labor of love and does not have any ads or sponsors. To support the show, please consider recommending a book from LearnDjango.com, signing up for the free weekly Django News newsletter, or learning more about Button a simpler deployment story for Django. -
Working with Django ImageField
<![CDATA[ Working with Django ImageField Django ImageField is great solution to associate images with your models. It is also a field that I most often have some issues with (because saving images is a bit more complicated than say text or a number). For this reason I decided to write this post as a future reference to myself and hopefully it will help someone else too. To even work with the ImageField you need the Pillow package. pip install Pillow When specifying the field definition, there is an option to select the directory where the images will be stored. For example: header_image = models.ImageField(upload_to='blog-images/') This is a relative path inside the media directory. Make sure you have the MEDIA_ROOT configured in your settings file. Saving images to ImageField There are numerous ways of saving actual image inside this field. The easier option is to use ModelForm, which you can just save (assuming it is valid) in your view and done. However, you need to include the request.FILES while creating the form like this: form = NewImageForm(request.POST, request.FILES) And for a brief visit to the HTML, the <form> needs special definition too in a form of the enctype attribute. <form method="post" … -
Django and Pydantic
This article looks at how to integrate Pydantic with a Django application. -
The Unexpected Find That Freed 20GB of Unused Index Space
Every few months we get an alert from our database monitoring to warn us that we are about to run out of space. Usually we just provision more storage and forget about it, but this time we were under quarantine, and the system in question was under less load than usual. We thought this is a good opportunity to do some cleanups that would otherwise be much more challenging. To start from the end, we ended up freeing more than 70GB of un-optimized and un-utilized space without dropping a single index or deleting any data! Using conventional technics such as rebuilding indexes and tables we cleared up a lot of space, but then one surprising find helped us clear an additional ~20GB of unused indexed values! This is what the free storage chart of one of our databases looked like in the process: Free space over time (higher means more free space) Table of Contents The Usual Suspects Unused Indexes Index and Table Bloat Clearing Bloat in Indexes Activating B-Tree Index Deduplication Clearing Bloat in Tables Using pg_repack The "Find" The "Aha Moment" Utilizing Partial Indexes Bonus: Migrating with Django ORM Prevent Implicit Creation of Indexes on Foreign Keys Migrate … -
Using Django Check Constraints to Prevent the Storage of The Empty String
Here’s another use case for creating a database constraint with Django’s CheckConstraint class. By default, a model CharField will store any string that the database supports. This includes the empty string, which is often inappropriate. For example, imagine we have a Team model, representing a group that users can belong to. We started by giving it a unique name: from django.db import models class Team(models.Model): name = models.CharField(max_length=120) class Meta: constraints = [ models.UniqueConstraint( name="%(app_label)s_%(class)s_name_unique", fields=["name"], ), ] Whilst seemingly reasonable, this model definition allows the creation of teams with an empty name. Such a team object is likely to break other parts of our application. For example, links might not display or unexpected errors may occur due to name being falsey. We could try to prevent the creation of empty-named teams with form validation, but that does not prevent creation of bad data through other processes, such as bulk imports. To ensure all the data in our system is valid, we need a database constraint. Here we want to add a minimal database constraint that ensures the length of name is greater than 0. Let’s walk through that now. First, we need to register the Length function for use … -
SOCCR: the framework I use for decision briefs
In my previous article, I wrote about gathering consensus before a decision. Several folks asked for more detail about how I structure those consensus-gathering and decision-making exercises. There’s a specific format I find helpful, which I remember by the acronym SOCCR. Read on for an explanation and example! -
Are Django and Flask Similar?
Maybe you’re new to web development in Python, and you’ve encountered the two most popular Python web frameworks, Django and Flask, and have questions about which one you should use. Are Django and Flask similar tools for building web applications? Yes, Django and Flask share many similarities and can both make great websites, but they have some different development philosophies which will attract different types of developers. What do I know about this? -
Recap of 2020 and Resolutions for 2021
Recap of 2020 I got a job saving the planet For years I've been worried about climate change. I've tried to live a mostly ecologically friendly life, and this year I dived in with making compost for the garden. However, seeing the lack of consistent political will to correct the problem has had me worried. So I was delighted that when I started to look for jobs in the autumn I was contacted by several firms attempting to address the problem. I've always thought that finance is a great motivator, albeit all-too-often the results are negative (the petroleum and coal industries are examples). Ultimately I went with Octopus Energy, a company that is to borrow a phrase, disrupting the legacy power industry in areas with free-er energy markets (UK, Australia, Germany, Texas, Japan). They have embraced renewable energies as a source of power, which is good because it is cheaper than fossil fuels. Even if customers don't believe in global climate change they won't be able to ignore the fact renewables are a cheaper source of energy. In any case, I can't begin to say how wonderful it is being part of a company whose mission is to address climate … -
Developing a Single Page App with Flask and Vue.js
The following is a step-by-step walkthrough of how to set up a basic CRUD app with Vue and Flask. -
Django News - New Wagtail and Documentation Sprint - Jan 29th 2021
News Wagtail Documentation Sprint A Wagtail Sprint is occurring February 4th and 5th, 2021 focused on documentation: tooling, writing, editing, content reorganization, design etc. It will be run from Torchbox’s offices in the UK, where anyone is welcome to join us, if it’s safe and legal, but we expect most people to participate remotely. wagtail.io Wagtail 2.11 just released Features include internationalization and improved image and document management. wagtail.io Articles Efficient Reloading in Django’s Runserver With Watchman Watchman is an efficient file watcher open sourced by Facebook, for which Django support was added in 2.2. In this article, Adam Johnson demonstrates how to use it with runserver for improved performance. adamj.eu Reading CloudFlare headers in a Django middleware Adam breaks down how to find a client’s IP address when using a CDN like Cloudflare. adamj.eu 5 Tips to Speed up Your Docker Image Build Docker is powerful but can be very time consuming. Here are 5 good tips for speeding up your image builds. vsupalov.com Which Django Version Should I Use? Matt Layman provides some advice on thinking about which Django version to use in your projects. mattlayman.com Sponsored Link Tackle Architecture Issues on Your Complex Django Codebase. As a … -
Customer Feature - Building SaaS #89
In this episode, I show you how to take a feature idea from nothing to something. We added new UI, wrote a new view, a new form, and all the associated test code to prove that the feature works. My customer wants the ability to complete a task on any day she desires. The feature flow looks like: Click a calendar icon next to a task on a student’s course page. -
Cleaning up a required process when you quit
Some time ago, I moved a bunch of our devops tools into a Makefile. I'm not sure exactly what the benefit was then, but there have been some challenges. One of these was related to having to run multiple processes when performing a task, but cleaning up the dependencies when we finish our task. Specifically, we run a websocket server in production that uses Redis for PubSub. We can safely assume the developer is running redis already, since the rest of the platform also depends upon it. However, to collect the changes from Postgres and publish them into Redis, we use a custom django management command. All this does is listen for postgres notifications and forward them to redis. $ ./manage.py relay Mostly we don't keep this running in development, unless you need to be running the websocket code locally for testing. It is a hassle to remember to start a process and then kill it when you are done, so it would be convenient to start the relay command, then start our websocket worker, and clean up both processes when we quit the worker. This _can_ be done in a Makefile command: {% highlight make %} websocket: $(shell trap … -
Cleaning up a required process when you quit
Some time ago, I moved a bunch of our devops tools into a Makefile. I'm not sure exactly what the benefit was then, but there have been some challenges. One of these was related to having to run multiple processes when performing a task, but cleaning up the dependencies when we finish our task. Specifically, we run a websocket server in production that uses Redis for PubSub. We can safely assume the developer is running redis already, since the rest of the platform also depends upon it. However, to collect the changes from Postgres and publish them into Redis, we use a custom django management command. All this does is listen for postgres notifications and forward them to redis. $ ./manage.py relay Mostly we don't keep this running in development, unless you need to be running the websocket code locally for testing. It is a hassle to remember to start a process and then kill it when you are done, so it would be convenient to start the relay command, then start our websocket worker, and clean up both processes when we quit the worker. This _can_ be done in a Makefile command: {% highlight make %} websocket: $(shell trap …