Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
[Django Tutorial] Connect MySQL Database in Django Framework
If you are looking forward to connect your MySQL database with python code that check the following guide: In order to connect your MySQL Database in Django Framework, you should do the following: Install MySQL package Configure your settings.py Make Migrations Install MySQL Package First install MySQL via pip from your terminal with the following -
Django Static Files and Templates
Static files like CSS, JavaScript, and fonts are a core piece of any modern web application. Django provides tremendous flexibility around _how_ these files are used, however this often leads … -
Giving Django Project a “Two Scoops” Configuration
Years back I bought a physical copy of Two Scoops of Django 1.11 after seeing it highly recommended in a book called Hello Web App by Tracy Osborn. Little did I know it was way over my head at the time. With the release of Two Scoops of Django 3.X, and with a lot of recent practice, the book is now only slightly over my head, so I’ve been trying to implement more of the practices recommended in the book. I’ve also been continuing to use Docker and Docker Compose after learning the basics in Django for Professionals by Will Vincent. Fixing Problems? Early on in Two Scoops, the authors discuss how the standard project layout from django-admin startproject leaves a lot to be desired. I definitely have NOT experienced that pain because I don’t have the skills to make any complex projects. I do, however, see the value in getting comfortable with a new layout. It teaches you how some of the module inheritance in Django works. Python import statements are one of the most challenging things for me, personally, so this is a good way to train your coding skills. Let’s talk about two different project layouts. Standard … -
Huey as a minimal task queue for Django
Are you considering adding a task quee to your Django project? Then this article should be useful to you. Adding a task queue will allow you to: Run longer-running processes outside the request-response cycle handled by Django. Actually gunicorn or uwsgi in production. Run scheduled tasks by not relying on crontab. This usually entails management commands or other forms of standalone scripts. Each needing all environment variables loaded correctly. When I was “younger” task queue with Django project meant celery task queue. Now that I’m “older” there are simpler alternatives. The simplest I found was Huey. But the ideas presented here apply to evaluating all task queues for your Django project. Background Frustrated with celery and django-celery In December 2019 I was taking a Django project from Python 2 to 3. This project relied on celery and its integration for Django for asynchronous task processing. Github project link here. This work was mostly done back in 2012-2015. celery’s “Django integration” part was the first problematic part. “Problematic” in the sense that it was not being actively maintained. And Python 3 support was only “planned” at the time. Besides, by testing celery with my Python3 setup I realised how “heavy” it … -
July 16th and 17 Live Instruction of our Django Crash Course
The authors of Two Scoops of Django are offering live instruction of the Django Crash Course. This isn't a live stream, but a Zoom-powered class that isn't going to be recorded. We're going to walk-through the book together with students. If you get stuck, there will be at least two members of the Feldroy team available to help. Each course day will be seven hours long, including an hour-long break for lunch. Attendees will receive: Hours of instruction in building web apps by noted authors and senior programmers An invite to both July 16th and July 17 class days The Django Crash Course e-book (if you already bought one, we'll send you a discount code for $19.99 off the online class) Membership in our forthcoming online forums Class prerequisites: Basic knowledge of the Python programming language Computer with permissions to install software Internet fast enough to join online meetings We're selling the course for the introductory price of just $99 and space is limited, so register today! -
July 16th and 17th Live Instruction of our Django Crash Course
The authors of Two Scoops of Django are offering live instruction of the Django Crash Course. This is a live interactive class conducted via Zoom conferencing software. We're going to walk-through the book together with students. If you get stuck, there will be at least two members of the Feldroy team available to help. Each course day will have two sessions each 3 hours long, as well as an hour long break between sessions. Attendees will receive: Hours of instruction in building web apps by noted authors and senior programmers An invite to both July 16th and July 17th class days, starting at 9AM PST (4PM UTC) The Django Crash Course e-book (if you already bought one, we'll send you a discount code for $19.99 off the online class) Membership in our forthcoming online forums when they are activated Class prerequisites: Basic knowledge of the Python programming language Computer where you are allowed to install software (No work restrictions) Internet fast enough to join online meetings Topics Covered: Setting up a development environment Cookiecutter for rapidly accelerating development Django Forms Class-Based Views Models Templates Admin Writing Django tests PyTest Factories Best Practices the Two Scoops of Django Way Proven patterns … -
July 15th, 16th and 17th Live Instruction of our Django Crash Course
The authors of Two Scoops of Django are offering live instruction of the Django Crash Course. This is a live interactive class conducted via Zoom conferencing software. We're going to walk-through the book together with students. If you get stuck, there will be at least two members of the Feldroy team available to help. Each course day will have two sessions each 3 hours long, as well as an hour long break between sessions. Attendees will receive: Hours of instruction in building web apps by noted authors and senior programmers An invite to both July 16th and July 17th class days, starting at 9AM PST (4PM UTC) The Django Crash Course e-book (if you already bought one, we'll send you a discount code for $19.99 off the online class) Membership in our forthcoming online forums when they are activated Class prerequisites: Basic knowledge of the Python programming language Computer where you are allowed to install software (No work restrictions) Internet fast enough to join online meetings Topics Covered: Setting up a development environment Cookiecutter for rapidly accelerating development Django Forms Class-Based Views Models Templates Admin Writing Django tests PyTest Factories Best Practices the Two Scoops of Django Way Proven patterns … -
Where Does the Data Go?
Full show notes are available at https://www.mattlayman.com/django-riffs/6. -
Episode 6 - Where Does the Data Go?
On this episode, we will learn about storing data and how Django manages data using models. Listen at djangoriffs.com. Last Episode On the last episode, we saw Django forms and how to interact with users to collect data. Setting Up A relational database is like a collection of spreadsheets. Each spreadsheet is actually called a table. A table has a set of columns to track different pieces of data. Each row in the table would represent a related group. -
Deploying Django to AWS with Docker and Let's Encrypt
In this tutorial, we'll deploy a Django app to AWS EC2 with Docker and Let's Encrypt. -
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, … -
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 …