Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Maps with Django (part 2): GeoDjango, PostGIS and Leaflet
A quickstart guide to create a web map with the Python-based web framework Django using its module GeoDjango, the PostgreSQL database with its spatial extension PostGIS and Leaflet, a JavaScript library for interactive maps. -
Know Your ORM | Where do objects come from?
Note: This is the first installment of our new series Know Your ORM. Stay tuned for more. So, you have been learning Django since a few days or weeks. You have worked with Django ORM and Django QuerySet API. And, you are totally familiar with this li... -
Managing concurrency in Django using select_for_update
A tutorial on how one can use select_for_update to lock a Django queryset until the transaction it is in is committed in order to handle concurrency. -
Django JSON Response safe=False
Hi👋 everyone, I'm happy to see my self writing blogs to you once again after a while due to some reasons. So, today; I would be sharing with you shortly, why safe=False is important in rendering {JSON} data in Django. Firstly, what is JSON? JSON si... -
My Zuri x i4G experience
Photo by Karolina Grabowska from Pexels Picture being the sub-team lead of your team and having no idea about how to go about the project. Lol!! Earlier this year, I applied for a free software developer program for absolute beginners organized by... -
Django News - New CPython Developer-in-Residence - Jul 16th 2021
News Wagtail 2.12.6 and 2.13.4 released Wagtail 2.12.6 and 2.13.4 bug fixes were released. See their changelog for more details. github.com Python Software Foundation News: Łukasz Langa is the inaugural CPython Developer-in-Residence! The PSF and the Python Steering Council are pleased to announce that the inaugural Developer-in-Residence role will be held by core develope... blogspot.com htmx 1.5.0 has been released! htmx is a popular way to add Javascript functionality to your Django site without writing any JavaScript yourself. htmx.org Events Meetup with talks | Meetup Thu, Aug 26, 2021, 5:00 PM: Do you want to share something? Then this is a great chance! Come prepared or unprepared with your Django/Python talk, short, medium and long. Got an idea? Please tell us: meetup.com Articles Python Type Hints - How to Avoid “The Boolean Trap” by Adam Johnson “The Boolean Trap” is a programming anti-pattern where a boolean argument switches behaviour, leading to confusion. In this post we’ll look at the trap in more detail, and several ways to avoid it in Python, with added safety from type hints. adamj.eu Control Runaway Postgres Queries With Statement Timeout A well tuned production Postgres database is capable of easily running thousands or up to … -
Django vs. Laravel - Ultimate Head to Head Comparison
Despite mobile development's popularity and the demand for it rising, web development has been getting a great deal of attention, and the technologies are evolving at an accelerated pace. Especially with the rise of new development concepts such as P... -
My Journey in Programming So Far ; 16months of Programming
"Computer programming is the process of writing code that instructs how a computer, application or software program performs or behave. At its most basic, computer programming is a set of instructions to facilitate specific actions. If you're wonder... -
How to use HtmlWebpackPlugin to load Webpack bundle in Django
I will show you how use HtmlWebpackPlugin to load Webpack bundle in Django without ANY Django 3-party package -
Making Sense Of Settings
In the last Understand Django article, we looked at a storage concept in Django called sessions. Sessions help us answer questions like “How does Django know when a user is logged in?” or “Where can the framework store data for a visitor on your app?” With this article, you’ll learn about Django settings and how to manage the configuration of your application. We’ll also look at tools to help you to be extra effective with settings. -
Django Implied Relationship
A little while ago, Alec McGavin put up a post on the Kogan blog about [Custom Relationships in Django](https://devblog.kogan.com/blog/custom-relationships-in-django). This is a really cool way to get a relationship in Django that exists in the database, but cannot be modelled correctly in Django. For instance, this could be data in the database that does not have a Foreign Key, either because it's legacy data, or because it's possible either side of the relationship might be added to the database before the other, rather than the normal order in a database where the target table of the FK is always added to first. However, I have another slighly different situation where an implied relationship exists, but should not be stored directly. Consider the following data structures: {% highlight python %} class Employee(models.Model): name = models.TextField() class EmploymentPeriod(models.Model): employee = models.ForeignKey( Employee, related_name='employment_periods', on_delete=models.CASCADE, ) valid_period = DateRangeField() class Meta: constraints = [ ExclusionConstraint( name='employment_overlap', expressions=[ ('employee', RangeOperators.EQUAL), ('valid_period', RangeOperators.OVERLAPS), ] ) ] class Shift(models.Model): employee = models.ForeignKey( Employee, related_name='shifts', on_delete=models.CASCADE, ) date = models.DateField() start_time = models.TimeField() duration = models.DurationField() employment_period = Relationship( EmploymentPeriod, from_fields=['employee', 'date'], to_fields=['employee', 'valid_period'], ) @property def start(self): return datetime.datetime.combine(self.date, self.start_time) @property def finish(self): return self.start + … -
Django File Uploads: How to Upload Images and Files
Today I'm going to cover how to add user document and image file uploads to your Django project as a simple HTML form and Django ModelForm. I'm using Bootstrap 5 for some basic styling. Django Media Files First configure your media upload settings before creating and uploading the form. Add Media URL to Django settings mysite > mysite > settings.py MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') Head over to the settings.py file and specify the MEDIA_URL and MEDIA_ROOT. They are not specified by default. Install Pillow Windows Command Prompt (env) C:\Users\Owner\Desktop\Code\env\mysite> pip install Pillow Also install Pillow for media upload support. Add Media URL to Django URLs mysite > mysite > urls.py from django.contrib import admin from django.urls import path, include from django.conf import settings #add this from django.conf.urls.static import static #add this urlpatterns = [ path('admin/', admin.site.urls), path('', include ('main.urls')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) Next, go to the mysite > urls.py and add the helper function above. Keep in mind it only works when DEBUG is set to True and the URL specified in the settings is local (i.e. /media/ not https://media.site.com/). Now, when an image is uploaded in development, it is added to a … -
Developing REST API Using Django REST Framework (DRF)
Introduction This is a sample project for exploring the development of REST APIs using Django REST Framework (DRF). Setting Up Django 1. Create new Django Project To create your Django project from scratch (make sure to have Django installed): $ djan... -
Django Regx
I will write more -
Django Detector Faces test
system detector faces in framework django. Link: https://github.com/eticialima/django_face_detection -
How to secure SaaS custom domain names
This is a guide on how BrandSSL can help companies set up fully-secured custom domain names for SaaS or e-commerce customers, without handling certificates or requiring any integration with external APIs. The custom domain name problem in SaaS and E... -
Django Waffle: Quick intro for dynamic feature toggling
<![CDATA[ Django Waffle: Quick intro for dynamic feature toggling Before we look at Django Waffle let's briefly talk about what "feature flags" mean. What are feature flags? Feature flags (also known as toggles and switches) are feature that lets you turn features of your app on and off. This can be simple admin toggle, or more sophisticated logic like showing new feature to 20 % of your users. The key is that you don't need to release new version of your app to do these modifications. Installing Django Waffle First steps towards feature flags with Django Waffle is the installation. pip install django-waffle And then we add waffle to the INSTALLED_APPS in settings. INSTALLED_APPS = [ 'waffle', ] And also to middleware: MIDDLEWARE = [ 'waffle.middleware.WaffleMiddleware', ] And as a last preparation step, run the migrations: python3 manage.py migrate Using Django Waffle switches Switches are powerful yet easy to configure and use. Switch needs just a name and whether it is active or not. Let's make this a practical example. First step is to define the switch in Django Admin. I am going to use show_new_sidebar for the demonstration. Once the switch is created, I can base logic in views … -
Django News - Django + htmx - Jul 9th 2021
News Wagtail 2.13.3 Bugfix release for Wagtail 2.13.3. github.com Events What’s New in Wagtail Webinar on July 13th & 15th A virtual Wagtail conference with information on the Wagtail vision for the next 2 years, new features/packages, live demos, and more. wagtail.io Articles How to Name Django Migrations (and Why It's Important) Proper migration names are important. This article covers how Django's migration system works and tips for making their names more human readable. nextlinklabs.com One Database Transaction Too Many A deep dive look at how a bug was created around accidentally sending hundreds of users messages they got paid when they didn't. hakibenita.com What You Should Know About The Django User Model A nice overview of Django User Model limitations and workarounds. simpleisbetterthancomplex.com Probably Are Gonna Need It: Application Security Edition Jacob Kaplan-Moss's list of “Probably Are Gonna Need It” security features for your web app – things that you should build up-front, not wait until you need them (when it’s already too late). jacobian.org PAGNIs: Probably Are Gonna Need Its Simon Willison's You Ain’t Gonna Need It (YAGNI) list of features you shouldn’t add just because it might be useful in the future—only write code when it solves … -
Book Updates Are Out!
We've updated the latest editions of both of our Django books: Two Scoops of Django 3.x: Best Practices for the Django Web Framework A Wedge of Django: Covers Python 3.8 and Django 3.x Current Status We're not ready to call them the "final" versions yet, but we're getting closer. Keep watching for further details as we continue to work on both books. All Updates Included Your one-time purchase includes the above updates as well as all future ones to these editions of the books. Everyone who has purchased either book should now be able to log in and download the latest PDF and ePub versions of their book. Trouble Downloading Your Update? If you can't access your download, email support [at] feldroy.com with the name and email your original purchase was under. We'll look up your order and help you get your update. Kindle Owners: Use the ePub Instead of Mobi In the past we included both .epub and .mobi file formats with the download. With this update we are dropping support for the now-archaic .mobi format. While a few very old Kindle devices without software updates can only use .mobi files, almost all Kindle owners should be able to … -
What You Should Know About The Django User Model
The goal of this article is to discuss the caveats of the default Django user model implementation and also to give you some advice on how to address them. It is important to know the limitations of the current implementation so to avoid the most common pitfalls. Something to keep in mind is that the Django user model is heavily based on its initial implementation that is at least 16 years old. Because user and authentication is a core part of the majority of the web applications using Django, most of its quirks persisted on the subsequent releases so to maintain backward compatibility. The good news is that Django offers many ways to override and customize its default implementation so to fit your application needs. But some of those changes must be done right at the beginning of the project, otherwise it would be too much of a hassle to change the database structure after your application is in production. Below, the topics that we are going to cover in this article: User Model Limitations The username field is case-sensitive The username field validates against unicode letters The email field is not unique The email field is not mandatory A … -
Probably Are Gonna Need It: Application Security Edition
My list of “Probably Are Going To Need It” security features for your web app – things that you should build up-front, not wait until you need them (when it’s already too late). -
Django 3.2 Update for “Speed Up Your Django Tests” Released
I released my book “Speed Up Your Django Tests” over a year ago, in May 2020. Since then, we’ve seen two major Django releases, including a whole bunch of test-related changes, some of which I worked on as part of the book. Today I’m releasing the first update for SUYDT. The update brings the existing content up to date with Python 3.9, Django 3.2, and some future changes for Django 4.0. It also includes some new sections on mocking time and parallelizing tests. And for those who with e-readers, it now comes as an ePub file, alongside the original flavour PDF (one purchase gives you both formats!). This update is free for existing readers, and does not increase the price. You can buy it now on Gumroad. For those outside of the richest top 50 countries by GDP, there’s a 50% discount. The book has a changelog at the end of the “Introduction” chapter. Here’s the entry for this update: Added ePub file to the release. Thanks to Mike Lissner and Paolo Melchiorre for requesting and testing it. Upgraded to Python 3.9 and Django 3.2 and updated content to reflect changes. Added Mock Time section to the “Targeted Mocking” chapter, … -
Django 3.2 Update for “Speed Up Your Django Tests” Released
I released my book “Speed Up Your Django Tests” over a year ago, in May 2020. Since then, we’ve seen two major Django releases, including a whole bunch of test-related changes, some of which I worked on as part of the book. Today I’m releasing the first update for SUYDT. The update brings the existing content up to date with Python 3.9, Django 3.2, and some future changes for Django 4.0. It also includes some new sections on mocking time and parallelizing tests. And for those who with e-readers, it now comes as an ePub file, alongside the original flavour PDF (one purchase gives you both formats!). This update is free for existing readers, and does not increase the price. You can buy it now on Gumroad. For those outside of the richest top 50 countries by GDP, there’s a 50% discount. The book has a changelog at the end of the “Introduction” chapter. Here’s the entry for this update: Added ePub file to the release. Thanks to Mike Lissner and Paolo Melchiorre for requesting and testing it. Upgraded to Python 3.9 and Django 3.2 and updated content to reflect changes. Added Mock Time section to the “Targeted Mocking” chapter, … -
htmx - Carson Gross
htmx@htmx_org on TwitterhyperscriptBig Sky Softwaredjango-htmxRapid Prototyping with Django, htmx, and Tailwind CSSSupport the ShowThis podcast does not have any ads or sponsors. To support the show, please consider visiting LearnDjango.com, Button, or Django News. -
Custom Permission Classes in Django REST Framework
This article looks at how to build custom permission classes in Django REST Framework (DRF).