Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Why does Python raise ModuleNotFoundError when modifying Django's INSTALLED_APPS?
Imagine we are installing the third party package django-cors-headers, which I maintain. Step one in its installation process is to install the package, so we run the command: python -m pip install django-cors-headers Step two is to add the module to our settings file’s INSTALLED_APPS. We might add it between the the Django contrib apps and our project’s own core app: INSTALLED_APPS = [ # Django contrib apps "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", "django.contrib.sites", "django.contrib.humanize", # Third-party apps "corsheaders" # Project apps "example.core" ] Unfortunately with the above INSTALLED_APPS has a bug. Can you spot it? It causes Python to raise the following ModuleNotFoundError when trying to run the server: $ python manage.py runserver Exception in thread django-main-thread: Traceback (most recent call last): File "/.../python3.8/threading.py", line 932, in _bootstrap_inner self.run() ... File "/.../site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/.../site-packages/django/apps/registry.py", line 91, in populate app_config = AppConfig.create(entry) File "/.../site-packages/django/apps/config.py", line 116, in create mod = import_module(mod_path) File "/.../python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1014, … -
How to add a .well-known URL to your Django site
The /.well-known/ URL path prefix is a reserved name space for serving particular static files used by other systems that might interact with your site. It was established by RFC 5785 and updated in RFC 8615. The IANA maintains a list of possible files in the Well Known URIs registry, but others are in wide use without official registeration (yet?). Some examples: /.well-known/acme-challenge is used for acknowledging HTTPS certificate challenges through Automatic Certificate Management Environment (ACME). This is used by popular free certificate authority Lets Encrypt. /.well-known/apple-app-site-association allows links to your domain to open an iOS app. /.well-known/assetlinks.json allows links to your domain to open an app on Android phones. /.well-known/security.txt is a proposed standard for hosting your site’s security policy that others should use when they find vulnerabilities in your site. To add such a URL to a Django application, you have a couple of options. You could serve it from a web server outside your application, such as nginx. The downside of this approach is that if you move your application to a different web server, you’ll need to redo that configuration. Also, you might be tracking your application code in Git, but not your web server configuration, … -
Django News - Wagtail Sub Teams, Django Admin 2FA and TOTP, Learning Django in 2020, and more - Jun 26th 2020
News Announcing Wagtail sub teams New teams who will complement the existing Wagtail core team, providing valuable expertise and drive for the teams’ respective areas of interest – for example internationalisation, user experience, or search. wagtail.io Articles How to Learn Django (2020) A guide to learning Django for beginners and intermediate/advanced developers. learndjango.com Adding two factor authentication to Django admin If you ever wanted to add Two-factor authentication (2FA) with Time-based one-time passwords (TOTP) support to the Django admin then this article is for you. timo-zimmermann.de Removing Sensitive Data From Git History If you have ever accidentally committed a password, API key, or secret into your git history, this is how you make it squeaky clean. dev.to What is the core of the Python programming language? A thoughtful take from Brett Cannon, a member of the Python Steering Council. snarky.ca Using Transactions to Make Django Tests Run Faster How to use the nested transaction mechanism of the Django testing framework to avoid reinitialization of your test models. gitconnected.com Conditional coverage Add conditional coverage to add or ignore tests as needed. sobolevn.me Sponsored Link Two Scoops of Django 3.x: Best Practices for the Django Web Framework The long-awaited update covers various … -
How to find what you want in the Django documentation
Many beginner programmers find the Django documentation overwhelming. Let's say you want to learn how to perform a login for a user. Seems like it would be pretty simple: logins are a core feature of Django. If you google for "django login" or search the docs you see a few … -
Hackathon App Part 2 - Building SaaS #62
In this episode, we took a break from the regular app to work on an app for a local hackathon that I’m participating in. This is the second week for the hackathon and in this stream, I apply the final touches to the application. We work on models, a template, and build an RSS feed using Django syndication contrib app. The final presentation for the app was the next day so it was crunch time to finish everything off. -
Adding two factor authentication to Django admin
As my dissatisfaction with WordPress grew, I did the only Reasonable Thing(tm) and decided to roll out my own CMS again. Which means I do not only have the joy of building a tool exactly fitting my needs, but I also have to build some of the functionality I would expect every production-ready system to provide. Account security in Django’s contrib.auth and contrib.admin package did not change a lot over the last decade, but in 2020 I expect some basic functionality from every system, like two factor authentication. As 2FA is missing in Djangos admin package, what is the Reasonable Decision(tm)? To add it myself, of course. You might see a trend of “reasonable yak shaving” here. (A small side note if you are working on a SaaS or web app right now: Account security is not a “premium feature” or a feature your users should have to pay for. It is basic functionality you should always provide to anyone, no matter if they are free or paid users, no matter which plan. And now back to our scheduled program!) This article assumes you have some familiarity with Python and Django; at least enough to create a new application, inherit … -
Adding two factor authentication to Django admin
As my dissatisfaction with WordPress grew, I did the only Reasonable Thing(tm) and decided to roll out my own CMS again. Which means I do not only have the joy of building a tool exactly fitting my needs, but I also have to build some of the functionality I would expect every production-ready system to provide. Account security in Django's contrib.auth and contrib.admin package did not change a lot over the last decade, but in 2020 I expect some basic functionality from every system, like two factor authentication. As 2FA is missing in Djangos admin package, what is the Reasonable Decision(tm)? To add it myself, of course. You might see a trend of "reasonable yak shaving" here. (A small side note if you are working on a SaaS or web app right now: Account security is not a "premium feature" or a feature your users should have to pay for. It is basic functionality you should always provide to anyone, no matter if they are free or paid users, no matter which plan. And now back to our scheduled program!) This article assumes you have some familiarity with Python and Django; at least enough to create a new application, inherit … -
Django JSONField attributes in admin filter
Django provides a JSONField which is useful to store JSON data and query on it. However, this is supported by PostgreSQL only. If you want to use JSONField with MySQL or MariaDB, you can use django-mysql-json-field. But in this post, we’ll be using inbuilt JSONField. Django provides us with a way to query on JSONfield but you can’t directly use JSONField’s attributes on admin as filters. In this post, I’ll be creating a Filter class for JSONField that can be used to create filters on the admin page. Let’s start with a simple model that has 1 JSONField. class MyModel(models.Model): jsonfield = JSONField() # few more fields... Populate this field with below data, we’ll use this data throughout the post as a reference. { "name": "Gaurav", "company": "pyscoop", "address": { "city": "Jaipur", "country": {"name": "India", "code": "IN"} } } Now suppose you want to create filters for JSONField properties/keys, for e.g. consider the above data, we want to show filters for company and city, something like below- class MyModelAdmin(admin.ModelAdmin): list_filter = ["jsonfield__company", "jsonfield__address__city"] But as expected, this will raise an error, we can’t use JSON field attributes for filtering like this. To support that we need to extend the inbuilt filter class. … -
Store Data With Models
In the previous Understand Django article, we encountered forms and how forms allow your application to receive data from users who use your site. In this article, you’ll see how to take that data and store it into a database so that your application can use that data or display it later. Setting Up Let’s figure out where your data goes before getting deep into how to work with it. -
Adding two factor authentication to Django admin
Adding two factor authentication to Django admin As my dissatisfaction with WordPress grew, I did the only Reasonable Thing™ and decided to roll out my own CMS again. Which means I do not only have the joy of building a tool exactly fitting my needs, but I also have to build some of the functionality I would expect every production-ready system to provide. Account security in Django’s contrib.auth and contrib.admin package did not change a lot over the last decade, but in 2020 I expect some basic functionality from every system, like two factor authentication. As 2FA is missing in Djangos admin package, what is the Reasonable Decision™? To add it myself, of course. You might see a trend of “reasonable yak shaving” here. (A small side note if you are working on a SaaS or web app right now: Account security is not a “premium feature” or a feature your users should have to pay for. It is basic functionality you should always provide to anyone, no matter if they are free or paid users, no matter which plan. And now back to our scheduled program!) This article assumes you have some familiarity with Python and Django; at least … -
Learning Wagtail - Kalob Taulein
LearnWagtail.comCoding for EverybodyKalob’s Udemy coursesawesome-wagtailThis Week in WagtailDjango Search TutorialHow to Get Hired as a Django DeveloperWagtail Slack channelFrom Burn-Out to $100M in ARR with Jason Cohen of WP Engine -
Securing a Containerized Django Application with Let's Encrypt
In this tutorial, we'll look at how to secure a containerized Django app running behind an HTTPS Nginx proxy with Let's Encrypt SSL certificates. -
How to search Google without using Google, the self-hosted way
Hello everyone! Last week I was talking with a friend and he was complaining about how Google knows everything about us, so I took the chance to recommend some degoogled alternatives: I sent him my blog, recommended DuckDuckGo, Nextcloud, Protonmail, etc. He really liked my suggestions and promised to try DuckDuckGo. A couple of days later he came to me a little defeated, because he didn’t like the search results on DuckDuckGo and felt bad going back to Google. So that got me thinking: Are there some degoogled search engines that use Google as the backend but respect our privacy? So I went looking and found a couple of really interesting options. Startpage.com According to their Wikipedia: Startpage is a web search engine that highlights privacy as its distinguishing feature. Previously, it was known as the metasearch engine Ixquick … On 7 July 2009, Ixquick launched Startpage.com to offer its service at a URL that is both easier to remember and spell. In contrast to Ixquick.eu, Startpage.com fetches results from the Google search engine. This is done without saving user IP addresses or giving any personal user information to Google’s servers. and their own website: You can’t beat Google when … -
How to search Google without using Google, the self-hosted way
Hello everyone! Last week I was talking with a friend and he was complaining about how Google knows everything about us, so I took the chance to recommend some degoogled alternatives: I sent him my blog, recommended DuckDuckGo, Nextcloud, Protonmail, etc. He really liked my suggestions and promised to try DuckDuckGo. A couple of days later he came to me a little defeated, because he didn’t like the search results on DuckDuckGo and felt bad going back to Google. So that got me thinking: Are there some degoogled search engines that use Google as the backend but respect our privacy? So I went looking and found a couple of really interesting options. Startpage.com According to their Wikipedia: Startpage is a web search engine that highlights privacy as its distinguishing feature. Previously, it was known as the metasearch engine Ixquick … On 7 July 2009, Ixquick launched Startpage.com to offer its service at a URL that is both easier to remember and spell. In contrast to Ixquick.eu, Startpage.com fetches results from the Google search engine. This is done without saving user IP addresses or giving any personal user information to Google’s servers. and their own website: You can’t beat Google when … -
Setup Django on Mac in 2020
There are many ways to setup Django on MacOS. Here is how to get started while keeping the flexibility to have projects in different versions of Django and different versions of Python too. -
Setup Django on Mac in 2020
There are many ways to setup Django on MacOS. Here is how to get started while keeping the flexibility to have projects in different versions of Django and different versions of Python too. -
How to Learn Django (2023)
__Note__: I gave a version of this tutorial at DjangoCon US 2022. You can see the video here: -
How to pull production data into your local Postgres database
Sometimes you want to write a feature for your Django app that requires a lot of structured data that already exists in production. This happened to me recently: I needed to create a reporting tool for internal business users. The problem was that I didn't have much data in my … -
Working with Celery and Django Database Transactions
This post details how to make Celery work nicely with Django Database Transactions. -
Django in Production - II
Second part of the series covering how to get your django project into production -
Django in Production - II
Second part of the series covering django app deployment Now we’re done with the basic django deployment using gunicorn, now it’s time to make our server scalable. Let’s add a reverse proxy server NGINX and serve our site on port 80. NGINX Installation If you’re using Ubuntu, run the following commands: sudo apt-get update sudo apt-get install nginx Now you can check the status of nginx by running command: sudo systemctl status nginx NGINX Configuration So, for running NGINX you’ll need to write configuration files. They’re stored in the /etc/nginx/sites-available/ directory. Let’s first go into that directory by running: cd /etc/nginx/sites-available/ Now let’s create a file by doing: sudo touch django.conf And now let’s open the file in the editor by doing: sudo nano django.conf Hint: We need to use sudo here because this directory is present in root and not inside our home directory. Then paste the below config inside it. server { server_name server_domain_or_ip; location / { include proxy_params; proxy_pass http://localhost:8000; } } In place of server_domain_or_ip you’ll put either IP address or the domain of your website. So NGINX uses this concept where you can have multiple configuration files as backup stored under /etc/nginx/sites-available/. But the active … -
Django News - No DjangoCon US this year ☹ - Jun 19th 2020
News DjangoCon US 2020 is Canceled After 12 consecutive years of DjangoCons in the United States, we’ve decided to cancel DjangoCon US 2020. djangoproject.com Django 3.1 Beta 1 Released Django 3.1 beta 1 is now available. It represents the second stage in the 3.1 release cycle and is an opportunity for you to try out the changes coming in Django 3.1. djangoproject.com Wagtail Space US 2020 – Call For Proposals The Wagtail Space US CFP deadline is open until July 1, 2020. google.com 2020 Python Software Foundation Board of Directors Election Results The 2020 Python Software Foundation Board of Directors election has concluded. See the results! blogspot.com Articles Postgres websearch in Django 3.1 Django 3.1 includes a new Postgres SearchQuery feature that allows human-formatted search queries. jamesturk.net Optimizing Django ORM Queries If you love optimization articles where they present SQL queries next to Django ORM calls, then you are in for a treat. schegel.net Use Pathlib in Your Django Settings File Get a jump on Django 3.1 and switch to pathlib in your projects. adamj.eu How I manage multiple development environments in my Django workflow using Docker compose A practical Docker Compose overview for how to handle both development and … -
Working with Celery and Django Database Transactions
This post details how to make Celery work nicely with Django Database Transactions. -
Django in Production - I
-
Django in Production - I
Hello djangonauts, today I want to talk about how to run django in production. Introduction So, you might have finished developing that project you were building for your client, and now it’s time to deploy your project on a server and make it accessible to public. But you’re confused on how to proceed further? I was too, but not anymore. The reason why I decided to write this series is that when I had to deploy my project, I had to spend hours searching about it and then read up multiple articles about it, but even then they didn’t cover all the essential details. So that’s what prompted me to write this series, and I am going to go over my setup for running django in production. First thing, I wanna clear up is that when you run your django server using the command: python manage.py runserver This starts up a development server, that is provided by the Django Team only for the purpose of development, you are not supposed to run your projects in production using it. In production, you’ll have to use a WSGI server such as Gunicorn or uWSGI, which I’m going to cover as well. Deployment …