Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Mercurial Mirror For Django 4.2 Branch
Slightly late, but here’s the 4.2 mirror. As usual, read-only, and aimed at production (aka “using django on servers “), not development (aka “commit”). -
Backend Development 101 with Django REST Framework
If you’re familiar with Python, you’ve most certainly heard of Django, but may not know what it is used for and why people like it so much. We will first run through a ‘backend development 101’ crash-course, then talk about Django’s take on backend development and what Django REST Framework provides on top of it. Finally we will add a feature to an example Django app and do some live coding. -
Backend Development 101 with Django REST Framework
If you’re familiar with Python, you’ve most certainly heard of Django, but may not know what it is used for and why people like it so much. We will first run through a ‘backend development 101’ crash-course, then talk about Django’s take on backend development and what Django REST Framework provides on top of it. Finally we will add a feature to an example Django app and do some live coding. -
An introduction to Django Simple History
Wouldn’t it be useful if we could document changes in our life and revisit them later at will? It would allow us to better analyze situations, remember what we were thinking, or help us remember how we got to our current state. Although no such tool currently exists for changes in life, one such tool does exist in Django. It is called django-simple-history. Django-simple-history stores Django model state on every create, update, or delete database operation; it can even revert back to old versions of a model, record which user changed a model, interact with multiple databases, and more. Rather than making code changes, django-simple-history gives us the ability to view and perform many of the changes via the admin interface. Let’s imagine we are creating a simple Polling application and our models.py file looks like this: from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') published = models.BooleanField(default="False") def __str__(self): return self.question How do we get django-simple-history to work on our application? Install django-simple-history: pip install django-simple-history In the settings.py file, Add simple_history to INSTALLED_APPS: INSTALLED_APPS = [ # ... 'simple_history', ] The historical models can track which user made each change. To automatically populate … -
Single-pages without the single-page with django2-tables, django-filter, and htmx
Introduction I've been meaning to use htmx since it came out, but I've never had time, nor the occasion. Now the opportunity finally came to refactor an old Django which uses the Datatable jQuery plugin. I wanted to try something fresh, and htmx seemed the way to go, paired with a couple of great libraries: django2-tables and django-filter. Let's see how they play well together! Please, take this post as personal notes, don't expect a step-by-step tutorial :-) The theory htmx is a JavaScript library for building dynamic user interfaces which lets you enrich HTML elements with "magic" attributes. With htmx, any actionable HTML element can make XHR requests. The magic comes from two htmx attributes: hx-get hx-target hx-get basically says: when the user clicks this element, make a GET request to the given URL, then swap the content of hx-target with the partial response. (POST requests are also supported). The basic principle behind htmx used in the context of server-side web frameworks is the following: if the frontend request comes from htmx, we return a partial HTML fragment instead of the whole document. In Django, this translates to: if the request comes from htmx, we return a partial template … -
Running your Django project with __main__.py
I don’t like Django’s manage.py. My gripes against it are: The plethora of files that clutter the root directory of our repos annoys me. manage.py is just one more in a long line of those. In my opinion, there are more “Pythonic” ways to execute code. In a previous post, I talked about how you can move the code into your project and use packaging tools to create a manage.py on your PATH during installation. In this post, we’ll look at another approach using __main__.py What is __main__.py (and __main__)? The Python docs do a good job of explaining this topic, so I’ll give you the tl;dr here. __main__.py provides a command line interface to a Python package. It can be executed with python -m mypackage. Here are some common ones you may have seen in the wild: python -m pip python -m venv python -m json.tool You may also be surprised to learn that python -m django can be used in place of the django-admin command. 🤯 The “magic” here is that each one of those packages has a __main__.py which defines what it should do when run from the command line. In each of these, you’ll see a … -
Using pyproject.toml in your (Django) project
Back in 2018, I wrote about using setup.py in your Django/Python project. Five years later, setup.py is being phased out in favor of pyproject.toml. I'm a big fan of this change. With setup.py you could really go off the rails making everything dynamic or even executing malicious code during the installation process. In contrast, pyproject.toml moves the ecosystem towards a configuration file that can be parsed without executing arbitrary code. You can read more about the rationale behind pyproject.toml in PEP-517, PEP-518, PEP-621, and PEP-660. Creating your pyproject.toml file If you're using poetry, pdm, or any of the other newer Python build systems, you're already using pyproject.toml. How about folks that are using plain old pip or pip-tools? You can still take advantage of this new file format and ditch setup.py and/or setup.cfg as well. Most third-party tooling supports configuration via the tool section defined in PEP-518. To start, define the build system for your project. To avoid introducing new tools, we're going to use good ol' setuptools: [build-system] requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" Next, define your project and its dependencies: [project] name = "myproject" version = "1.0" dependencies = [ "dj-database-url", "django==3.2.*", "gunicorn", "psycopg2", "whitenoise", ] [project.optional-dependencies] dev … -
Django Dev Made Easy: How to Run Multiple Processes Simultaneously
As a Django developer, I have to run multiple processes while developing, such as the Django server, a JavaScript compiler, and Celery. Launching these processes separately can be time-consuming and tedious. Just try opening three terminal windows, and you'll understand what I mean. Finally, I found a solution … Read now -
Django News - Django Fellow Call for Applicants - Feb 10th 2023
News DSF calls for applicants for a Django Fellow After five years as part of the Django Fellowship program, Carlton Gibson is stepping down. There is a new Fellow position available. Please consider applying. djangoproject.com Python 3.11.2 Python 3.11.2 is the newest major release of the Python programming language, and it contains many new features and optimizations. python.org Python 3.11.2, 3.10.10, and 3.12.0 alpha 5 These releases include bugfixes, security releases, and even a new alpha release. blogspot.com Sponsored Link SaaS Pegasus Django-powered SaaS boilerplate for your project. Get a head start and launch faster than you dreamed possible. saaspegasus.com Articles Standout features in Django 4.2 Django Fellow Mariusz Felisiak walks us through some of the more notable features coming in Django 4.2 in early April 2023. fly.io A New Mentorship Program An overview of Caktus Group's Mentorship program. caktusgroup.com What Django Deployment is Really About A high-level look at four overall areas that make Django deployment somewhat challenging. walters.click pre-commit: How to create hooks for unsupported tools Adam Johnson shows us how to use pre-commit for unsupported tools like stylelint and jpegoptim. adamj.eu Events DjangoCon Europe - Call for Proposals Full information is now available on talks at DjangoCon … -
Weeknotes (2023 week 6)
Weeknotes (2023 week 6) Rust I made some progress learning Rust. I don’t have to look up each character and function and am slowly getting a feel for the language, unwrapping and the borrow checker, so that’s nice. I don’t have a use for it for now, but we’ll see. feincms3-data and data cycles I added support for loading data with cyclic dependencies to feincms3-data. This is useful e.g. when having Django models where you have a ForeignKey("self") and you want to use feincms3-data to insert a new copy of some object and its dependencies. Editing trees in the Django administration interface I’m back to one of my favorite (not) activities which is making tree-shaped data editable in the Django administration panel. FeinCMS and later django-mptt augments the changelist with some drag drop behavior. There’s no undo functionality though so making errors is potentially really bad. feincms3 uses a separate page for moving nodes around. Now I’m working on a Preact-based project which also doesn’t use drag drop but which also allows inserting nodes, not just moving nodes around. I doubt I can make it reusable enough to make it useful for feincms3 but we’ll see. -
Documenting Python Code and Projects
This article looks at why you should document your Python code and how to generate project documentation with Sphinx and OpenAPI. -
Deploying a Django App to Google App Engine
This tutorial looks at how to deploy a Django application to Google App Engine. -
Weeknotes (2023 week 5)
Weeknotes (2023 week 5) A long time has passed since I tried writing week notes. Oh well, here we go again. No committment here, just hope. Podcasts Really got into listening to podcasts in the last few weeks. That’s new for me, I never enjoyed listening to people talk when I could also listen to music. So, that’s interesting. Podcasts I like a lot: The Ezra Klein Show, Django Chat and some others where I haven’t yet listened enough to list them here. Advent of Code I knew that Advent of Code existed quite long already but I never dug into it. I participated in the 2022 Advent of Code and enjoyed it a lot. I have long been unsecure regarding my programming skills since I do not have a formal CS background so it felt really good to be able to solve many problems with only a little help. Definitely not all of them though. It definitely was fun and I’m still working through other years a bit. Python is the most fun, JavaScript is sometimes nice. Rust gives me a hard time (or I’m giving myself a hard time) but the upside is that solving even easy puzzles … -
Django News - Django security release for 4.1.6, 4.0.9, and 3.2.17 - Feb 3rd 2023
News Django security releases issued: 4.1.6, 4.0.9, and 3.2.17 The new security release fixes a potential denial-of-service attack. djangoproject.com DjangoCon US 2023 Confirmed It will take place in Durham, North Carolina, at the Durham Convention Center on October 16-20, 2023. More details to come. djangocon.us Articles Python’s “Disappointing” Superpowers Luke Plan's long essay on does Python have Superpowers. lukeplant.me.uk The Django Developer's Guide to Vite An easy way to add JavaScript to your Django projects via Vite, which bills itself as next generation frontend tooling. ctrlzblog.com Django: migrations by choice How to update choice lists in Django models without rolling a migration every time. dev.to Forum django-crispy-forms 2.0a1 - Show & Tell The alpha release for django-crispy-forms is out. This is a widely used package and the maintainers are looking for people to test it out and provide any feedback. djangoproject.com Tutorials Official Django REST Framework Tutorial - A Beginners Guide A 4.1 update to this lengthy beginner-friendly guide to the official Django REST Framework tutorial. Also comes with GitHub repo of the final code. learndjango.com LearnDjango - How to Install Django A beginner-friendly guide to properly installing Django 4.1. It covers the command line, installing Python 3.11, virtual environments, … -
MongoDB - Mark Smith
DjangoCon Europe 2023 @judy2k on Twitter Django Integration with MongoDB DjangoCon Europe 2022 - The (Python) Magic of Django: A Tour of the Codebase PyCon Italia 2022: Stupid Things I’ve Done With Python Everything You Know About Mongo is WrongDjangoCon Europe 2020 - How to Get on This Stage (And What To Do When You Get There) PyCon Australia 2019 - It’s Pythons All the Way Down: Python Types and Metaclasses Made Simple 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. -
Django Static Files and Templates
Static files like CSS, JavaScript, and fonts are a core piece of any modern web application. They are also typically confusing for Django newcomers since Django provides tremendous flexibility around … -
Securing FastAPI with JWT Token-based Authentication
This tutorial shows how to secure a FastAPI application with JWT Token-based Authentication. -
How to Install Django
This tutorial covers how to properly install the latest version of [Django (4.1)](https://www.djangoproject.com/) and [Python (3.11)](https://www.python.org). As the [official docs note](https://docs.djangoproject.com/en/dev/topics/install/), if you are already familiar with the command line, … -
Django News - Bleach derecation - Jan 27th 2023
News Bleach 6.0.0 release and deprecation Bleach, the Python library for sanitizing and linkifying text in HTML, released 6.0.0 and was deprecated because html5lib is no longer actively maintained. bluesock.org The PSF is hiring a Security Developer-in-Residence! The Python Software Foundation (PSF) is happy to announce the launch of a year-long security enhancement initiative that will include a security audit and the creation of a new Security Developer-in-Residence role. blogspot.com Sponsored Ad 5th Annual Python Web Conf Early Bird Tickets On Sale! Early bird tickets (25% off) for the Python Web Conference, organized by Six Feet Up, expire Wednesday, Feb. 1 at 11:59pm ET (UTC -5h). 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 How to simulate a broken database connection for testing in Django An overview of the challenges and three different solutions. neilkakkar.com Reflection on DjangoCon US 2022 Some recaps, favorite talks, and general impressions of DjangoCon US 2022. caktusgroup.com Configuring Sphinx Auto-Doc with projects having Django dependencies How to make it so projects with Django as a dependency benefit from Sphinx's auto-documentation … -
Integrating the Masonite ORM with FastAPI
This tutorial looks at how to use the Masonite ORM with FastAPI. -
Introducing: YAMS (Yet Another Media Server)!
Hello internet 😎 I’m here with a big announcement: I have created a bash script that installs my entire media server, fast and easy 🎉 TL;DR I’ve created YAMS. A full media server that allows you to download and categorize your shows/movies. Go to YAMS’s website here: http://yams.media or check it on Gitlab here: https://gitlab.com/rogs/yams. A little history When I first set up my media server, it took me ~2 weeks to install, configure and understand how it’s supposed to work: Linking Sonarr, Radarr, Jackett together, choosing a good BitTorrent downloader, understanding all the moving pieces, choosing Emby, etc. My plan with YAMS is to make it easier for noobs (and lazy people like me) to set up their media servers super easily. I have been working on YAMS for ~2 weeks. The docker-compose file has existed for almost 2 years but without any configuration instructions. Basically, you had to do everything manually, and if you didn’t have any experience with docker, docker-compose, or any of the services included, it was very cumbersome to configure and understand how everything worked together. So basically, I’m encapsulating my experience for anyone that wants to use it. If you don’t like it, at … -
Introducing: YAMS (Yet Another Media Server)!
Hello internet 😎 I’m here with a big announcement: I have created a bash script that installs my entire media server, fast and easy 🎉 TL;DR I’ve created YAMS. A full media server that allows you to download and categorize your shows/movies. Go to YAMS’s website here: http://yams.media or check it on Gitlab here: https://gitlab.com/rogs/yams. A little history When I first set up my media server, it took me ~2 weeks to install, configure and understand how it’s supposed to work: Linking Sonarr, Radarr, Jackett together, choosing a good BitTorrent downloader, understanding all the moving pieces, choosing Emby, etc. My plan with YAMS is to make it easier for noobs (and lazy people like me) to set up their media servers super easily. I have been working on YAMS for ~2 weeks. The docker-compose file has existed for almost 2 years but without any configuration instructions. Basically, you had to do everything manually, and if you didn’t have any experience with docker, docker-compose, or any of the services included, it was very cumbersome to configure and understand how everything worked together. So basically, I’m encapsulating my experience for anyone that wants to use it. If you don’t like it, at … -
Django News - Django 4.2 Alpha 1 Released - Jan 20th 2023
News Django 4.2 alpha 1 released Django 4.2 alpha 1 is now available. It represents the first 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 Git security vulnerabilities announced tl;dr Upgrade to the latest Git version as soon as possible. github.blog GitHub Copilot Litigation From November 2022 but still relevant. It is a class-action lawsuit against GitHub Copilot which trained its AI systems on public GitHub repositories (and potentially private as well) including Django's. githubcopilotlitigation.com Articles PyDev of the Week: Tim Schilling - Mouse Vs Python Tim is a longtime Django user who currently works on multiple third-party packages including django-debug-toolbar. He also gave a Django debugging tutorial at DjangoCon US last year. pythonlibrary.org Why I Like Nox Tox is a command-line tool that automates testing in multiple Python environments. Nox is a similar tool that aims to simplify the usage of Tox by using standard Python files instead of INI-config files. hynek.me Sponsored Link Meet Wagtail, the #1 Django-powered CMS 100% open source. Powered by Python & Django. Built for editors and developers with excellent documentation. Trusted by Google, NASA and hundreds of thousands of … -
Configuring Sphinx Auto-Doc with projects having Django dependencies
How to make it so projects with Django as a dependency benefit from Sphinx's auto-documentation features. The Problem I want to be able to document open source packages with Sphinx (ex. xocto) and have Sphinx automatically document the Django helpers. This isn't quite the same as documenting a Django project, so I wasn't sure if the otherwise awesome sphinxcontrib-django would be the right tool. Fortunately, there's a solution that doesn't require any additional packages. The Solution Configuration First, in the Sphinx docs folder, create a file called django_settings.py and add the following: """ Minimal file so Sphinx can work with Django for autodocumenting. Location: /docs/django_settings.py """ # INSTALLED_APPS with these apps is necessary for Sphinx to build # without warnings & errors # Depending on your package, the list of apps may be different INSTALLED_APPS = [ "django.contrib.auth", "django.contrib.contenttypes", ] Next, at the top of Sphinx's conf.py, add the following: # docs/conf.py import os import sys import django # Note: You may need to change the path to match # your project's structure sys.path.insert(0, os.path.abspath("..")) # For discovery of Python modules sys.path.insert(0, os.path.abspath(".")) # For finding the django_settings.py file # This tells Django where to find the settings file os.environ["DJANGO_SETTINGS_MODULE"] … -
Multi-Region Python Applications
This article shows at how to enable multi-region support in a Python application.