Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Rapid Prototyping with Flask, htmx, and Tailwind CSS
This tutorial looks at how to add htmx and Tailwind CSS to Flask to reduce the amount of time it takes to create and style an interactive front-end. -
How I Integrated Zapier into my Django Project
As you might know, I have been developing, providing, and supporting the prioritization tool 1st things 1st. One of the essential features to implement was exporting calculated priorities to other productivity tools. Usually, building an export from one app to another takes 1-2 weeks for me. But this time, I decided to go a better route and use Zapier to export priorities to almost all possible apps in a similar amount of time. Whaaat!?? In this article, I will tell you how. What is Zapier and how it works? The no-code tool Zapier takes input from a wide variety of web apps and outputs it to many other apps. Optionally you can filter the input based on conditions. Or format the input differently (for example, convert HTML to Markdown). In addition, you can stack the output actions one after the other. Usually, people use 2-3 steps for their automation, but there are power users who create 50-step workflows. The input is managed by Zapier's triggers. The output is controlled by Zapier's actions. These can be configured at the website UI or using a command-line tool. I used the UI as this was my first integration. Trigger events accept a JSON … -
How I Integrated Zapier into my Django Project
As you might know, I have been developing, providing, and supporting the prioritization tool 1st things 1st. One of the essential features to implement was exporting calculated priorities to other productivity tools. Usually, building an export from one app to another takes 1-2 weeks for me. But this time, I decided to go a better route and use Zapier to export priorities to almost all possible apps in a similar amount of time. Whaaat!?? In this article, I will tell you how. What is Zapier and how it works? The no-code tool Zapier takes input from a wide variety of web apps and outputs it to many other apps. Optionally you can filter the input based on conditions. Or format the input differently (for example, convert HTML to Markdown). In addition, you can stack the output actions one after the other. Usually, people use 2-3 steps for their automation, but there are power users who create 50-step workflows. The input is managed by Zapier's triggers. The output is controlled by Zapier's actions. These can be configured at the website UI or using a command-line tool. I used the UI as this was my first integration. Trigger events accept a JSON … -
Running Python in the Browser with WebAssembly
In this tutorial, you'll build a Python code editor in the browser using WebAssembly (WASM), via Pyodide, and CodeMirror. -
Django News - Django 4.0.4, 3.2.13, and 2.2.28 security releases - Apr 15th 2022
News Django security releases issued: 4.0.4, 3.2.13, and 2.2.28 These Django releases fix several significant security issues. Also, note that this is the final Django 2.2 update. Users should upgrade to Django 3.2 for ongoing LTS (Long-Term Support). djangoproject.com Wagtail 2.16.2 and 2.15.2 bug fixes Wagtail 2.16.2 and 2.15.5 contain bug fixes and updates Jinja2 compatibility. github.com Sponsored Ad Building Intelligent Space Infrastructure Cognitive Space is building intelligent infrastructure for the new space domain with Python at the core. We are looking for passionate Python developers in backend, dev ops, and machine learning. 🖖 workable.com Articles Permissions in Django A look at Django's powerful out-of-the-box permission system and how to assign permissions to users and groups in order to authorize them to perform specific actions. testdriven.io Optimize large Django migrations An interesting look at optimizing a large Django migration with the help of Paginator. gabnotes.org Generic Functionality without Generic Relations A very interesting technique for minimizing database queries with aggregate content that shares generic functionality. blogspot.com fstring.help: Python f-string guide A short reference for how to use f-strings. fstring.help Follow the pink pony: A story of CSRF, managed services, and unicorns Django 4.0 introduced a minor change to how Django … -
Great Expectations Data Quality Testing
Great Expectations is a shared, open standard for data quality. It helps data teams eliminate pipeline debt, through data testing, documentation, and profiling https://greatexpectations.io/ -
Great Expectations Data Quality Testing
Great Expectations is a shared, open standard for data quality. It helps data teams eliminate pipeline debt, through data testing, documentation, and profiling https://greatexpectations.io/ -
Django’s Rough Edges - Keryn Knight
Keryn on GitHubKeryn on Twitter Django Triage & Review Teamdjango-technicalerrors Compiling by xkcdSupport 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. -
Professionalism: What is “professionalism” and why am I writing about it?
I’m starting a new series on professionalism: the set of workplace behaviors that are generally expected at work. These behaviors are largely unspoken, but they do exist: there are consequences for violating them. In this series, I aim to write down some of these rules and explore their implications. Eventually, I hope to have a solid list of what “professional behavior” really means. -
Permissions in Django
This article looks at how to leverage Django's default permission system to assign permissions to users and groups. -
Is my advice too mercenary?
A criticism of some of my writing is that it’s too mercenary. Some see my advice as coldly calculating, too focused on individual outcomes over collective ones, and implicitly distrustful of others. I think this is fair criticism! It’s not exactly what I’m going for, but it’s a fair reading. However, there’s more to it than that, I want to address it (and defend myself, just a little bit). -
Generic Functionality without Generic Relations
When you have some generic functionality like anything commentable, likable, or upvotable, it’s common to use Generic Relations in Django. The problem with Generic Relations is that they create the relationships at the application level instead of the database level, and that requires a lot of database queries if you want to aggregate content that shares the generic functionality. There is another way that I will show you in this article. I learned this technique at my first job in 2002 and then rediscovered it again with Django a few years ago. The trick is to have a generic Item model where every other autonomous model has a one-to-one relation to the Item. Moreover, the Item model has an item_type field, allowing you to recognize the backward one-to-one relationship. Then whenever you need to have some generic categories, you link them to the Item. Whenever you create generic functionality like media gallery, comments, likes, or upvotes, you attach them to the Item. Whenever you need to work with permissions, publishing status, or workflows, you deal with the Item. Whenever you need to create a global search or trash bin, you work with the Item instances. Let’s have a look at … -
Generic Functionality without Generic Relations
When you have some generic functionality like anything commentable, likable, or upvotable, it’s common to use Generic Relations in Django. The problem with Generic Relations is that they create the relationships at the application level instead of the database level, and that requires a lot of database queries if you want to aggregate content that shares the generic functionality. There is another way that I will show you in this article. I learned this technique at my first job in 2002 and then rediscovered it again with Django a few years ago. The trick is to have a generic Item model where every other autonomous model has a one-to-one relation to the Item. Moreover, the Item model has an item_type field, allowing you to recognize the backward one-to-one relationship. Then whenever you need to have some generic categories, you link them to the Item. Whenever you create generic functionality like media gallery, comments, likes, or upvotes, you attach them to the Item. Whenever you need to work with permissions, publishing status, or workflows, you deal with the Item. Whenever you need to create a global search or trash bin, you work with the Item instances. Let’s have a look at … -
Django News - New PSF Executive Director - Apr 8th 2022
News PyPI Organization Account Roadmaps PyPI is looking for users who would be interested in participating in user interviews (25-30 minutes or less and would take place every 2 weeks.) python.org PSF News: PSF Welcomes New Executive Director Deb Nicholson The Python Software Foundation (PSF), the non-profit home of the Python programming language community, welcomes Deb Nicholson as its new Executive Director. blogspot.com Python Release Python 3.11.0a7 Python 3.11.0a7 is the last of seven planned alpha releases. python.org Sponsored Ad Building Intelligent Space Infrastructure Cognitive Space is building intelligent infrastructure for the new space domain with Python at the core. We are looking for passionate Python developers in backend, dev ops, and machine learning. 🖖 workable.com Articles How to Squash and Rebase a Git Branch It can be tiresome to rebase feature branches with many commits. Adam Johnson shows how rebase and squash commits together. adamj.eu XSS Filter Evasion - OWASP Cheat Sheet Series This article is focused on providing application security testing professionals with a guide to assist in Cross Site Scripting testing. You are guaranteed to find a few dozen that you have never seen before. owasp.org Those HTML Attributes You Never Use Louis Lazaris describes and demonstrates … -
Your last one-on-one: what to do instead of an exit interview
Say you agree with me that exit interviews are dangerous for employees, but you’re a kind, empathetic manager who’s built a team with high trust. You’d never dream of retaliation, are open to feedback – even if it’s harsh. You don’t want to put your departing direct in an uncomfortable or threatening position, but you’d like to know what they have to say! What then? -
Amsterdam python meetup
(Summaries of a talk at the April 2022 py.amsterdam meetup). Interesting takeaways from book 'Test Driven Development With Python' - Rok Klancar The book "test driven development with python" is available for free onine at https://www.obeythetestinggoat.com/ . The subtitle is test driven development (TDD) for the Web, with Python, Selenium, Django, JavaScript and pals... It is a quite thick book, but the author is very enthousiastic about programming and the subject of testing, so it actually very readable. The book consists of three parts: The basics of test driven development and django. So he starts out with explaining web development with django, just enough for having something real to test. Web development sine qua non. He's serious, at the end of part two you'll actually have deployed a web application. (And you'll have tested it, of course.) More advanced topics in testing. The core idea of test driven development is that you first write a (failing!) test and only then you write the code to get the tests to pass. The first test in the book is whether you have installed django (which you haven't yet). That sets the tone for the rest of the book :-) The whole time … -
Exit Interviews Are a Trap
It’s tempting to air your grievances at your exit interview. Don’t. There’s almost no upside to speaking up, and tremendous potential downside. Avoid exit interviews if you can. If you must go, be totally bland; say nothing negative. -
How to sort case insensitively with empty strings last in Django
Imagine you have something like this in Django: class MyModel(models.Models): last_name = models.CharField(max_length=255, blank=True) ... The most basic sorting is either: queryset.order_by('last_name') or queryset.order_by('-last_name'). But what if you want entries with a blank string last? And, you want it to be case insensitive. Here's how you do it: from django.db.models.functions import Lower, NullIf from django.db.models import Value if reverse: order_by = Lower("last_name").desc() else: order_by = Lower(NullIf("last_name", Value("")), nulls_last=True) ALL = list(queryset.values_list("last_name", flat=True)) print("FIRST 5:", ALL[:5]) # Will print either... # FIRST 5: ['Zuniga', 'Zukauskas', 'Zuccala', 'Zoller', 'ZM'] # or # FIRST 5: ['A', 'aaa', 'Abrams', 'Abro', 'Absher'] print("LAST 5:", ALL[-5:]) # Will print... # LAST 5: ['', '', '', '', ''] This is only tested with PostgreSQL but it works nicely. If you're curious about what the SQL becomes, it's: SELECT "main_contact"."last_name" FROM "main_contact" ORDER BY LOWER(NULLIF("main_contact"."last_name", '')) ASC or SELECT "main_contact"."last_name" FROM "main_contact" ORDER BY LOWER("main_contact"."last_name") DESC Note that if your table columns is either a string, an empty string, or null, the reverse needs to be: Lower("last_name", nulls_last=True).desc(). -
How to sort case insensitively with empty strings last in Django
Imagine you have something like this in Django: class MyModel(models.Models): last_name = models.CharField(max_length=255, blank=True) ... The most basic sorting is either: queryset.order_by('last_name') or queryset.order_by('-last_name'). But what if you want entries with a blank string last? And, you want it to be case insensitive. Here's how you do it: from django.db.models.functions import Lower, NullIf from django.db.models import Value if reverse: order_by = Lower("last_name").desc() else: order_by = Lower(NullIf("last_name", Value("")), nulls_last=True) ALL = list(queryset.values_list("last_name", flat=True)) print("FIRST 5:", ALL[:5]) # Will print either... # FIRST 5: ['Zuniga', 'Zukauskas', 'Zuccala', 'Zoller', 'ZM'] # or # FIRST 5: ['A', 'aaa', 'Abrams', 'Abro', 'Absher'] print("LAST 5:", ALL[-5:]) # Will print... # LAST 5: ['', '', '', '', ''] This is only tested with PostgreSQL but it works nicely. If you're curious about what the SQL becomes, it's: SELECT "main_contact"."last_name" FROM "main_contact" ORDER BY LOWER(NULLIF("main_contact"."last_name", '')) ASC or SELECT "main_contact"."last_name" FROM "main_contact" ORDER BY LOWER("main_contact"."last_name") DESC Note that if your table columns is either a string, an empty string, or null, the reverse needs to be: Lower("last_name", nulls_last=True).desc(). -
Django News - Django Day Copenhagen next week! - Apr 1st 2022
News PyCon US Keynote Speakers Keynote Speakers were announced for PyCon US, a hybrid event both online and in Salt Lake City, Utah, from April 27 to May 5, 2022. pycon.org Sponsored Ad Django Styleguide - A styleguide for Django projects, big and small. github.com Events Django Day Copenhagen 2022 A full day of Django talks in-person and with free streaming on April 8, 2022. djangoday.dk Articles You Probably Don’t Need Django’s get_user_model() Adam Johnson's take on a vanilla User import vs get_user_model(). adamj.eu Trailing URL Slashes in Django Why it's a good idea to add them and how Django works under-the-hood. learndjango.com The Real Reason To ‘Learn To Code’? Automating Your Life Don’t learn to code — learn to automate. medium.com Django Cheat Sheet An A-Z overview of setting up a new Django project. dev.to How to Make Django Raise an Error for Missing Template Variables Four techniques to check for missing template variables in Django. adamj.eu Updating A Many-To-Many Relationship In Django When working with Django's Many-To-Many relationship, forgetting to use the add method is a common gotcha. dev.to Tutorials Putting a Django site in maintenance mode How to create a Django maintenance mode middleware. medium.com Setting up … -
How to Be a Teapot in Django
HTCPCP, or Hyper Text Coffee Pot Control Protocol, was published as an April Fool’s joke 24 years ago today. It’s an HTTP extension for controlling coffee pots, and whilst it is a joke, it appears in various places around the web. HTCPCP adds one HTTP response code, “418 I’m a teapot”, which teapots can respond with if they are asked to brew coffee. As a registered status code, it has even made its way into the Python standard library’s HTTPStatus: In [1]: from http import HTTPStatus In [2]: HTTPStatus.IM_A_TEAPOT Out[2]: <HTTPStatus.IM_A_TEAPOT: 418> You can use HTTPStatus with Django to create a teapot page on your site. This will let you follow Google’s google.com/teapot page, so you can be one step closer to web scale! Throw a view in your project like: from http import HTTPStatus from django.shortcuts import render def teapot(request): return render( request, "teapot.html", status=HTTPStatus.IM_A_TEAPOT, ) Add a URL definition, such as at teapot/, and make a snazzy template. For a demo, I downloaded a sweet teapot GIF from gifcities.org: Great. That will be very useful, I’m sure. Fin May your tea always be perfectly brewed, —Adam -
PDF Courses Report - Building SaaS with Python and Django #132
In this episode, we added a final PDF report to the PDF bundle. This report was different than the other because there wasn’t a pre-existing HTML report to mimic. I built a report that shows all the completed course tasks for each student. -
PDF Courses Report - Building SaaS #132
In this episode, we added a final PDF report to the PDF bundle. This report was different than the other because there wasn’t a pre-existing HTML report to mimic. I built a report that shows all the completed course tasks for each student. -
Django the Good Parts - James Bennett
James’s personal websiteDjango in Depth talk at PyCon Montreal 2015Django the Good Parts at PyCon 2014 and slidesLet’s Build a Web Framework by Jacob Kaplan Moss at PyCon 2017How I’m Testing in 2020Against service layers in DjangoSupport 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 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 …