Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django File (and Image) Uploads Tutorial
This tutorial shows how to implement file and then image uploading with Django. We'll build a basic Instagram clone. ## Setup Whether you're on a Windows or Mac laptop the … -
Django Markdown Tutorial
[Markdown](https://daringfireball.net/projects/markdown/) is a popular text-to-HTML conversion tool for web writers. It is far easier to use than plain old HTML. Many/most static site generators provide a built-in way to write … -
Django Slug Tutorial
In this tutorial we will add slugs to a Django website. As noted in the [official docs](https://docs.djangoproject.com/en/dev/ref/models/fields/#slugfield): "Slug is a newspaper term. A slug is a short label for something, … -
Django Best Practices: Function-Based Views vs Class-Based Views
Django's use of both function-based views (FBVs) and class-based views (CBVs) causes a lot of confusion for newcomers. Why have multiple ways to do the same thing? And which one … -
The Home Stretch - Building SaaS #63
In this episode, we return to the homeschool application that I’m building. I’m in the final stretch of changes that need to happen to make the product minimally viable. We worked on a template, wrote some model methods, and did a bunch of automated testing. We started by adding students to the context of the students index page. With the students in the context, we updated the index page to display the list of students. -
Do you need a task queue in your web app?
Within your web application, some operations, or “tasks”, take an unpredictable time to run. Others take too long to have them executed within the web application’s request/response cycle. Adding a task queue will allow you to: Run longer-running tasks outside the request-response cycle handled by web framework. Actually gunicorn or uwsgi in a production Django1 setup. 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. Without a task queue Let’s say you want to send an email to a user when they submit a form. The process is shown below2: Figure 1. View sends email directly. No queue. This adds an unpredictable time to the expected response time. I.e. those 1-2 seconds taken to: talk to the email provider, over the network receive a response from the email provider, again over the network With a task queue With the task queue in place, the email sending part is done asynchronously. I.e. The unpredictable part is shifted onto the queue. And we don’t really care how long that takes; that is, for returing a response to the user. In case it fails, many task … -
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.… -
Speed Up Your Django Tests - Adam Johnson
Adam Johnson personal siteSpeed Up Your Django TestsPyCon UK 2016: Cleaner unit testing with the Arrange Act Assert patternDjango Software Foundation Teamstime-machineSHAMELESS PLUGSLearnDjango - Free tutorials and premium books -
[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
Static files like CSS, JavaScript, and fonts are a core piece of any modern web application. They are also typically confusing for Django newcomers since Django provides tremendous flexibility around … -
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 …