Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django authentication with Nuxt
In this tutorial you'll learn how to integrate a Nuxt application with Django Rest Framework session based authentication. In a previous post I explained how to setup a Django Rest Framework project for session-based authentication. If you didn't read it already, I suggest to take a look at that post before proceeding: Django Rest Framework authentication: the easy way Read more... Here we'll make one step further and we'll integrate a Nuxt web application with the backend we created in that tutorial. I created an example project on GitHub you can use to follow along with this tutorial. Table of Contents Create a simple Nuxt application Use docker-compose with Traefik to serve both frontend and backend from the same domain Add a login page to the web app Use Vuex store to handle user authentication Require authentication in other pages Conclusions Create a simple Nuxt application For the sake of this tutorial I'll create a simple Nuxt application from scratch. $ yarn create nuxt-app drf-authentication-frontend yarn create v1.22.18 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... [4/4] Building fresh packages... success Installed "create-nuxt-app@4.0.0" with binaries: - create-nuxt-app [###############################################################] 343/343 create-nuxt-app v4.0.0 ✨ Generating Nuxt.js project in drf-authentication-frontend ? Project … -
How to Make Django Raise an Error for Missing Template Variables
It’s all too easy to forget to pass a variable to your template, or make a typo in a variable name. Unfortunately, it can be quite hard to debug such mistakes, since Django’s default behaviour is to ignore the problem and render an empty string. In this post we’ll look at several techniques to check for missing template variables: Using the string_if_invalid option - the built-in option, but a bit cumbersome. With a Logging Filter that Raises Exceptions - this is my preferred technique. But it could break templates in your project that rely on the default missing variable beahviour. With a Logging Filter That Promotes Messages to Errors - you can use this to phase in the above exception-raising behaviour. With Jinja’s StrictUndefined - if you can switch your templates to render with Jinja, you can enable this option, as well as gain some other advantages. Alright, there’s plenty of soil to till, so let’s dig in! With The string_if_invalid Option The DTL has an option called string_if_invalid. Templates render this for missing variables, and it defaults to the empty string. The docs have more detail on how this works. You can configure it in your settings like so … -
You Probably Don’t Need Django’s get_user_model()
Django’s authentication system, django.contrib.auth, provides a built-in User model class. You can swap this to a different class with the AUTH_USER_MODEL setting, most easily at the start of the project. django.contrib.auth also provides a function called get_user_model(). This retrieves the current user model class, whether it is the built-in one or a swapped one. You can use this function like so: from django.contrib.auth import get_user_model User = get_user_model() def some_function(): for user in User.objects.all(): ... But in most Django code, you do not need to use get_user_model(), and you can instead use a vanilla import: from example.core.models import User def some_function(): for user in User.objects.all(): ... A vanilla import has several advantages; It’s less code It’s consistent with other model imports Your editor may be able to use it for autocomplete Linters and type checkers can use the class to guard against more errors get_user_model() is intended for use in reuseable Django apps, such as those you install from PyPI. Such apps cannot know what the user model class is, so they need to use get_user_model() to refer to it. Within a project, where you know what your user model class is, you can directly import it. Internally, get_user_model() performs … -
Django News - Python 3.10.4 and 3.9.12 released - Mar 25th 2022
News Python 3.10.4 and 3.9.12 released Python 3.10.4 and 3.9.12 fixes a regression in builds for Red Hat Enterprise Linux 6. python.org bugs.python.org is moving to GitHub Issues The migration from bugs.python.org to GitHub Issues is scheduled to start on Friday 25th in the evening (UTC). python.org Celery Docs Migrated The Celery Project's Docs are now hosted on: https://docs.celeryq.dev celeryq.dev Sponsored Ad Django Styleguide - A styleguide for Django projects, big and small. github.com Articles Responsive table with Django and htmx This article is a nice introduction to a lot of technologies including django-tables2, django-filter, htmx, and django-htmx. dev.to PyTest with Django REST Framework: From Zero to Hero An in-depth, highly opinionated guide on writing tests with PyTest with Django REST Framework. It's a treat. dev.to The 10 Most-Used Django Packages | LearnDjango.com A look at the top 10 Django-related downloads according to PyPI. learndjango.com Videos Building SaaS with Python and Django #130 - PDF Progress Report Another episode from Matt Layman focused on adding a report to a PDF bundle and refactors. youtube.com Sponsored Link Error monitoring for Django Developers. Track and debug exceptions in record time so you can get back to doing what you love. honeybadger.io Projects … -
PDF Attendance Report - Building SaaS with Python and Django #131
In this episode, we added a third PDF report to the PDF bundle. The patterns from previous reports made this one go faster, but I hit some small snags with the output of the PDF being crushed together. -
Flask vs Django (2022)
[Flask](https://palletsprojects.com/p/flask/) and [Django](https://www.djangoproject.com) are the two most popular [Python-based](https://www.python.org) web frameworks. Both are mature, open-source, and have many happy users. A natural question therefore is: which one to use? In … -
Trailing URL Slashes in Django
Among Django's many built-in features is [APPEND_SLASH](https://docs.djangoproject.com/en/4.0/ref/settings/#append-slash), which by default is set to `True` and automatically appends a slash `/` to URLs that would otherwise [404](https://en.wikipedia.org/wiki/HTTP_404). **Note**: The Chrome web … -
Django Best Practices: Models
Properly defining database models is arguably __the__ most important part of a new project, however Django provides us with tremendous flexibility around *how* we structure our models. There _is_ an … -
The 10 Most-Used Django Packages
Inspired by a past article on [The 22 Most-Used Python Packages in the World](https://medium.com/better-programming/the-22-most-used-python-packages-in-the-world-7020a904b2e), I teamed up with [Jeff Triplett](https://jefftriplett.com/about/) to investigate the top 10 Django packages based on [PyPI](https://pypi.org/) … -
Django News - Python Web Conference and Wagtail Space US next week - Mar 18th 2022
News Python 3.10.3, 3.9.11, 3.8.13, and 3.7.13 security and bugfix releases New maintenance releases with lots of security and bugfixes. python.org Python removes ‘dead batteries’ from standard library A slew of obsolete modules are slated to be dropped from Python, a possible prelude to a process for keeping the standard library cleaner. infoworld.com Sponsored Ad Django Styleguide - A styleguide for Django projects, big and small. github.com Events DjangoCon Europe 2022 Super early bird tickets are ending soon! All tickets include access to all 3 conference days (September 21 - 23) and the 2 sprints days (September 24 - 25). djangocon.eu Last call for PWC 2022 Last call for Python Web Conference (PWC) 2022 is next week, March 21-25, 2022. ti.to Last call for Wagtail Space US 2022 Wagtail Space US is virtual via Zoom or in-person at the Cleveland Public Library March 24-26. wagtail.space Django Day Copenhagen April 8th, 2022 Venue tickets are sold out but there will be a free streaming feed available. Sign up for a free ticket to be notified of the feed. djangoday.dk PyCon AU 2023 An announcement on the postponement of PyCon AU in 2022. The plan is for PyCon AU 2023 to be … -
PDF Progress Report - Building SaaS with Python and Django #130
In this episode, we added the next report to the PDF bundle. In the process of adding this report, I cleaned up some of the PDF generation code and refactored to some common patterns. -
Production APIs - Calvin Hendryx-Parker
Python Web Conference 2022Six Feet UpFLASHAmazon Fargatedjango-rest-knoxdjango-sesameSupport 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. -
How to run uWSGI
Given the cornucopia of options uWSGI offers it's really hard to figure out what options and settings are good for your typical web app. Normally you'd just balk and run something simpler with less knobs and dials, like mod-wsgi with Apache but alas, uWSGI is so flexible and has so many features that mod-wsgi lacks. If only it weren't so tricky to configure... First off, hands down, this is the most important setting - you should always start your configuration in strict mode. This will save you lots of pain and suffering if you ever fiddle with options. [uwsgi] # Error on unknown options (prevents typos) strict = true In general the most reliable concurrency model is processes, with no threads: # Formula: cores * 2 + 2 processes = %(%k * 2 + 2) You could enable threads (the threads option) and use less processes but that can be problematic for code that is CPU-bound or not thread-safe. I wouldn't enable the gevent plugin - you're just asking for trouble with all that monkey-patching. Essentially you're using more memory to avoid certain problems. Most of the useful uWSGI features rely on the master process, it's a pretty mandatory option … -
Django News - Understand Django Security - Mar 11th 2022
News This newsletter has passed 2,500 subscribers! A quick thank you to our readers as this newsletter just crossed 2,500 weekly subscribers. Our engagement is unusually high for a newsletter and we enjoy sharing news/articles/projects with the Django community each week. 🙏🏼 django-news.com Events Wagtail Space US schedule is live! The full schedule for the event, March 24-26 in Cleveland, Ohio is now live. wagtail.space Sponsored Ad Django Styleguide - A styleguide for Django projects, big and small. github.com Articles Understand Django #18: Security A detailed look at web security in general and how to implement best practices in Django. mattlayman.com Scaling Django with Postgres Read Replicas While this is not a new post, if you ever wondered how to scale Django with Postgres Read Replicas, this is worth reading. andrewbrookins.com Python Development Environment on macOS Monterey and Big Sur An opinionated tutorial on configuring a stock Mac system into a solid Python development environment. hackercodex.com Pretty and XSS-safe JSON rendering in the Django admin A concise way to pretty-format a read-only JSON field in the Django admin. niccolomineo.com Sponsored Link Error monitoring for Django Developers. Track and debug exceptions in record time so you can get back to doing … -
Security And Django
In the last Understand Django article, we learned about where apps slow down. We explored techniques that help sites handle the load and provide a fast experience for users. With this article, we will look at security. How does a Django site stay safe on the big, bad internet? Let’s find out. From Browser To DjangoURLs Lead The WayViews On ViewsTemplates For User InterfacesUser Interaction With FormsStore Data With ModelsAdminister All The ThingsAnatomy Of An ApplicationUser AuthenticationMiddleware Do You Go? -
Django News - Django bugfix release: 4.0.3 - Mar 4th 2022
News Django bugfix release: 4.0.3 Django 4.0.3 fixes several bugs in 4.0.2. Also, all Python code in Django is reformatted with black. djangoproject.com PyCon US 2022 Schedule Launch The schedule for PyCon US 2022 has been published! Registration will open on March 1, 2022, for Tutorials, Sponsor Workshops, Summits, Mentored Sprints for Diverse Beginners, and the PyLadies Auction blogspot.com Sponsored Link Error monitoring for Django Developers. Track and debug exceptions in record time so you can get back to doing what you love. honeybadger.io Articles `django-htmx` Now on Read the Docs As part of the django-htmx release there is now a built-in documentation site but with Sphinx and hosted on Read the Docs. adamj.eu Modal forms with Django+HTMX An article covering one pattern for implementing modal forms and HTMX. benoitblanchon.fr Python Project Setup – Virtual Environments and Package Management An overview of available ways to manage virtual environments and packages in Python. bas.codes Modern Python Environments - dependency and workspace management A 2nd(!) and very comprehensive overview of available tools for dependency and workspace management with Python. testdriven.io Deploying a Django Application to Elastic Beanstalk Walking through the steps for deploying a production-ready Django app to AWS Elastic Beanstalk. testdriven.io … -
PDF Debugging - Building SaaS with Python and Django #129
In this episode, I debugged the static file handling that my homeschool application is using when it generates PDF reports. Note: There was some stream trouble. This segment of the stream had no webcam video and was disconnected. Part 2 shows the successful completion of the PDF integration which you can see at https://www.youtube.com/watch?v=F5CBNNZMdxs. -
Django Community - Anna Makarudze
Anna’s personal siteDjangoCon US 2018 Keynote @amakarudze on TwitterDjango Events Foundation of North America (DEFNA)Site Reliability Engineering: How Google Runs Production SystemsSupport 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-htmx Now on Read the Docs
I’ve just released django-htmx 1.9.0. As part of this release, it now has a documentation site built with Sphinx, hosted on Read the Docs at django-htmx.readthedocs.io. The documentation looks a lot nicer than what can be fit in the GitHub README, especially thanks to the Furo theme. It’s also more digestible on several pages. I’ve also added a few sections, covering some useful tips for using htmx with Django: How to add htmx to your Django project. django-htmx does not include htmx, so you can upgrade the two separately. I covered how to download htmx into your project’s static files. This goes with my open PR to htmx to de-emphasize using unpkg.com directly. How to make htmx pass Django’s CSRF token. This is a commonly required pattern. It was previously covered only in the included “example project”, but that was not so easy to discover. How to do partial rendering. This is a neat trick for cutting down server side render times a bit. This techinque is also covered in the example project. The “tips” page may expand in the future with further techniques. Thanks to: Ben Beecher for doing initial Sphinx and Read the Docs setup in PR #194. … -
Rotterdam (NL) 2022 python meetup summaries
(Some summaries of a talk at the February 2022 Rotterdam python meetup). Technical note about running the live+online meetup The meetup was partly live, partly online. The technical setup worked surprisingly well: They had a microsoft Teams channel for the online folks. A laptop was connected to that same channel and showed it on a big screen via a beamer in the room for the "live" folks. The speakers had to connect to the Teams channel to show their slides both online and automatically also in the room. A big microphone gave pretty good sound, even though it was some four meters away from the speaker. Worked fine! Strange having a meeting without having to wrestle with hdmi adapters :-) Pandas and excel tables done properly - Thijs Damsma He showed https://github.com/VanOord/pandas-xlsx-tables When using a jupyter notebook and pandas, you can easily load csv files and do stuff with it. Make nice graphs, for instance. But... colleagues want xsl sheets.... So you can use a pandas xls exporter. But the output is a raw xls sheet. It works much better if you format the data in xls as a "table": "format as table". It sounds like it only formats it … -
Deploying a Django Application to Elastic Beanstalk
This tutorial shows how to deploy a Django Application to AWS Elastic Beanstalk. -
Modern Python Environments - dependency and workspace management
This article looks at the available tools for dependency and workspace management in Python. -
Django News - The Baked Data Architectural Pattern - Feb 25th 2022
News htmx 1.7.0 has been released! Multiple new features and improved documentation in the latest htmx release. htmx.org Django for APIs 4.0 Update is now available This is a major update to the book Django for APIs with new chapters on testing, deployment, Windows support, and loads more content. This post covers the full scope of changes. wsvincent.com Sponsored Ad Django Styleguide - A styleguide for Django projects, big and small. github.com Events Wagtail Space US 2022 CFP (last call) Wagtail Space US's deadline to submit is February 25, 2022 Talks will have the option of being pre-recorded, given live via Zoom, or given in-person at the venue (and broadcast over Zoom by our technician). For pre-recorded talks, we would ask the presenter to still be online during the talk broadcast to answer questions and audience feedback. google.com Articles The Baked Data Architectural Pattern An architectural pattern for publishing websites that provides many of the advantages of static site generators while ignoring most of their limitations. simonwillison.net Working with Static and Media Files in Django This article looks at how to work with static and media files in a Django project, locally and in production. testdriven.io How and why I … -
Form Features and CSS - Building SaaS with Python and Django #128
In this episode, we worked on a user requested feature that improves a workflow for task management in the homeschool app. After completing the feature, I returned to the PDF bundle project to add CSS styling to the PDF report. -
Managing a Django Project with Poetry
Poetry is relatively new packaging and dependency manager. It makes it very easy to upload libraries to PyPI, manage dependencies visually, and has a couple of handy features. Today, I'm not going to do a deep dive into how Poetry works and all its features. Today I just want to focus on how to configure it for a Django project.