Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
E-Commerce - Jacob Rief
Weekly Django Chat Newsletterdjango-cmsdjango-shopdjango-angulardjango-websocket-redisdjango-admin-sortable2django-fsmWeb components -
Monitoring Kubernetes InitContainers with Prometheus
Kubernetes InitContainers are a neat way to run arbitrary code before your container starts. It ensures that certain pre-conditions are met before your app is up and running. For example it allows you to: - run database migrations with Django or Rails before your app starts - ensure a microservice or API you depend on to [is running](https://www.magalix.com/blog/kubernetes-patterns-the-init-container-pattern) - register your app with an external tool, such as Consul for [health checks and service discovery](https://learn.hashicorp.com/consul/getting-started/services) Unfortunately InitContainers can fail and when that happens you probably want to be notified because your app will never start. Kube-state-metrics exposes plenty of of Kubernetes cluster metrics for Prometheus. Combining the two we can monitor and alert whenever we discover container problems. [Recently](https://github.com/kubernetes/kube-state-metrics/pull/762), a pull-request was merged that provides InitContainer data. The metric `kube_pod_init_container_status_terminated_reason` tells us why a specific InitContainer failed to run; whether it's because it timed out or ran into errors. To use the InitContainer metrics deploy Prometheus and kube-state-metrics. Then target the metrics server in your Prometheus scrape_configs to ensure we're pulling all the cluster metrics into Prometheus: ```yaml - job_name: 'kube-state-metrics' static_configs: - targets: ['kube-state-metrics:8080'] ``` `kube_pod_init_container_status_terminated_reason` contains the metric label `reason` that can be in five different states: - … -
De-Google my life - Part 5 of ¯ (ツ)_/¯: Backups
Hello everyone! Welcome to the fifth post of my blog series “De-Google my life”. If you haven’t read the other ones you definitely should! (Part 1, Part 2, Part 3, Part 4). At this point, our server is up and running and everything is working 100% fine, but we can’t always trust that. We need a way to securely backup everything in a place where we can restore quickly if needed. Backup location My backups location was an easy choice. I already had a Wasabi subscription, so why not use it to save my backups as well? I created a new bucket on Wasabi, just for my backups and that was it. There is my bucket, waiting for my sweet sweet backups Security Just uploading everything to Wasabi wasn’t secure enough for me, so I’m encrypting my tar files with GPG. What is GPG? From their website: GnuPG (GNU Privacy Guard) is a complete and free implementation of the OpenPGP standard as defined by RFC4880 (also known as PGP). GnuPG allows you to encrypt and sign your data and communications; it features a versatile key management system, along with access modules for all kinds of public key directories. GnuPG, also … -
De-Google my life - Part 5 of ¯ (ツ)_/¯: Backups
Hello everyone! Welcome to the fifth post of my blog series “De-Google my life”. If you haven’t read the other ones you definitely should! (Part 1, Part 2, Part 3, Part 4). At this point, our server is up and running and everything is working 100% fine, but we can’t always trust that. We need a way to securely backup everything in a place where we can restore quickly if needed. Backup location My backups location was an easy choice. I already had a Wasabi subscription, so why not use it to save my backups as well? I created a new bucket on Wasabi, just for my backups and that was it. There is my bucket, waiting for my sweet sweet backups Security Just uploading everything to Wasabi wasn’t secure enough for me, so I’m encrypting my tar files with GPG. What is GPG? From their website: GnuPG (GNU Privacy Guard) is a complete and free implementation of the OpenPGP standard as defined by RFC4880 (also known as PGP). GnuPG allows you to encrypt and sign your data and communications; it features a versatile key management system, along with access modules for all kinds of public key directories. GnuPG, also … -
Listen Notes - Wenbin Fang
Weekly DjangoChat NewsletterListen NotesThe Boring Tech Behind a One-Person Internet CompanySearch From the Ground Up @DjangoCon US 2019Django Search Tutorial -
Models from JSON(B)
One of the things we'll often try to do is reduce the number of database queries. In Django, this is most often done by using the [`select_related`](https://docs.djangoproject.com/en/2.2/ref/models/querysets/#select-related) queryset method, which does a join to the related objects, thus returning the data from those, and then automatically creates the instances for those objects. This works great if you have a foreign key relationship (for instance, you are fetching Employee objects, and you also want to fetch the Company for which they work). Tt does not work if you are following the reverse of a foreign key, or a many-to-many relation. You can't `select_related` to get all of the employee's locations at which she can work, for instance. In order to get around this, Django also provides a [`prefetch_related`](https://docs.djangoproject.com/en/2.2/ref/models/querysets/#prefetch-related) queryset method, that will do a second query and fetch all of the related objects for all of the objects in the initial queryset. This is evaluated at the same time as the initial queryset, so works pretty well during pagination, for example. But, we don't always want _all_ of the objects: sometimes we might only want the most recent related object. Perhaps we have a queryset of Employee objects, and we want … -
6 ways to speed up your CI
#### Waiting for CI to finish slows down development and can be extremely annoying, especially when CI fails and you have to run it again. Let's take a look into approaches on how to speed up your CI and minimize the inefficient time spent by developers when waiting on CI to finish. We'll go through 6 different methods to speed up CI: - Makisu as your Docker build tool - Caching between Stages - Concurrent Jobs for each Stage - Running Tests across all CPUs - Parallel Tasks - Autoscaling CI Runners ## Building Docker Images with Makisu + Redis KV storage We've tried three approaches; default image building with Docker using `--cache-from`, Google's Kaninko with `--cache=true` and Uber's Makisu with Redis KV storage. Kaniko is Google's image build tool which enables building images without a docker daemon, making it great for building images within a Kubernetes cluster as it is not possible to run a docker daemon in a standard Kubernetes cluster. Makisu is also an image build tool that does not rely on the docker daemon making it work great within a Kubernetes cluster and it also adds a couple of new things as e.g distributed cache support … -
Django asynchronous tasks without Celery
In this blog post I will guide you to implement Django asynchronous tasks without Celery. First of all I will define that I mean with the term “asynchronous task”. What are Django asynchronous tasks? Suppose that you want to perform a long running task in your Django web app, but you want to give an immediate response to the user without waiting for the task to finish. The task could be: sending an email, building a report, making a request to an external web service, etc. The response given to the user usually is a confirmation message that the task has started. Every task that could take some time to complete should not block the request-response cycle between the user and your application. If you Google for “Django asynchronous tasks” probably you’ll be directed to Celery as the way to implement asynchronous tasks with Django. Please don’t get me wrong: there is nothing wrong in Celery. Many successful projects use Celery in production with success. I also used Celery in a couple of projects, and it works well. What I find annoying is the additional effort. Celery is yet another service to configure, launch and maintain. Enter the uWSGI spooler … -
Django asynchronous tasks without Celery
In this blog post I will guide you to implement Django asynchronous tasks without Celery. First of all I will define what I mean with the term “asynchronous task”. Table of Contents What are Django asynchronous tasks? Enter the uWSGI spooler Install uwsgidecorators package Create the directory for the “spool files” Create a tasks module in your Django application Call the asynchronous task from your Django view Configure uWSGI to use the spooler Conclusion What are Django asynchronous tasks? Suppose that you want to perform a long running task in your Django web app, but you want to give an immediate response to the user without waiting for the task to finish. The task could be: sending an email, building a report, making a request to an external web service, etc. The response given to the user usually is a confirmation message that the task has started. Every task that could take some time to complete should not block the request-response cycle between the user and your application. If you Google for “Django asynchronous tasks” probably you’ll be directed to Celery as the way to implement asynchronous tasks with Django. Please don’t get me wrong: there is nothing wrong in … -
De-Google my life - Part 4 of ¯ (ツ)_/¯: Dokuwiki & Ghost
Hello everyone! Welcome to the fourth post of my blogseries “De-Google my life”. If you haven’t read the other ones you definitely should! (Part 1, Part 2, Part 3). First of all, sorry for the long wait. I had a couple of IRL things to take care of (we will discuss those in further posts, I promise ( ͡° ͜ʖ ͡°)), but now I have plenty of time to work on more blog posts and other projects. Thanks for sticking around, and if you are new, welcome to this journey! On this post, we get to the fun part: What am I going to do to improve my online presence? I began with the simplest answer: A blog (this very same blog you are reading right now lol) Ghost Ghost is an open source, headless blogging platform made in NodeJS. The community is quite large and most importantly, it fitted all my requirements (Open source and runs in a docker container). For the installation, I kept it simple. I went to the DockerHub page for Ghost and used their base docker-compose config for myself. This is what I came up with: version: '3.1' services: ghost: image: ghost:1-alpine restart: always ports: … -
De-Google my life - Part 4 of ¯ (ツ)_/¯: Dokuwiki & Ghost
Hello everyone! Welcome to the fourth post of my blogseries “De-Google my life”. If you haven’t read the other ones you definitely should! (Part 1, Part 2, Part 3). First of all, sorry for the long wait. I had a couple of IRL things to take care of (we will discuss those in further posts, I promise ( ͡° ͜ʖ ͡°)), but now I have plenty of time to work on more blog posts and other projects. Thanks for sticking around, and if you are new, welcome to this journey! On this post, we get to the fun part: What am I going to do to improve my online presence? I began with the simplest answer: A blog (this very same blog you are reading right now lol) Ghost Ghost is an open source, headless blogging platform made in NodeJS. The community is quite large and most importantly, it fitted all my requirements (Open source and runs in a docker container). For the installation, I kept it simple. I went to the DockerHub page for Ghost and used their base docker-compose config for myself. This is what I came up with: version: '3.1' services: ghost: image: ghost:1-alpine restart: always ports: … -
Caching
Weekly Django Chat newsletterDjango cache frameworkVarnish HTTP CacheRedisMemcacheddjango-qdjango-redisdjango-redis-cacheawesome-django repoHigh Performance Django book -
One Team’s Development Patterns With Vue.js and Django REST Framework
Within the past year, my development team at Caktus worked on a project that required a front-end framework to build a fast, easy-to-use product for a client. After a discussion of frameworks such as React, Vue, and Angular, and their approaches, our team settled on using Vue.js, along with a Django back-end with Django REST Framework (DRF). Initially, we chose Vue because we were more familiar with it, rather than its current competitor React, but as we worked on the product, we ended up having a number of team discussions about how to organize our code well and avoid extra code debt. This blog outlines some of the development patterns we chose as we worked through a number of issues, such as simplifying a multitude of almost identical Vuex mutations, finding a consistent way of holding temporary state, and working with nested objects on the front-end and back-end. Note: this blog post assumes familiarity either with Vue.js, or a similar front-end framework, like React or AngularJS. Issue 1: Almost Identical Mutations In our use of Vue.js, we chose to use the Vuex library for state management in a store, as recommended by the Vue documentation. Following Vuex documentation, we created … -
One Team’s Development Patterns With Vue.js and Django REST Framework
Within the past year, my development team at Caktus worked on a project that required a front-end framework to build a fast, easy-to-use product for a client. After a discussion of frameworks such as React, Vue, and Angular, and their approaches, our team settled on using Vue.js, along with a Django back-end with Django REST Framework (DRF). Initially, we chose Vue because we were more familiar with it, rather than its current competitor React, but as we worked on the product, we ended up having a number of team discussions about how to organize our code well and avoid extra code debt. This blog outlines some of the development patterns we chose as we worked through a number of issues, such as simplifying a multitude of almost identical Vuex mutations, finding a consistent way of holding temporary state, and working with nested objects on the front-end and back-end. -
Kenneth Love
Weekly DjangoChat NewsletterKenneth Love personal sitedjango-bracesGrowing Old Gracefully: On Being a Career Programmer by Carlton Gibson @DjangoCon Europe 2018Kenneth Love NewsletterThe Manager’s Path booksqljs.orgpgexercisessql-mysteriessql-murder-mystery in datasette -
Django – NGINX: deploy your Django project on a production server
Django – NGINX is a popular and well tested combination used to deploy web applications in production. In this post I will explain the steps needed to have your Django project deployed on a production server using Ubuntu 18.04. To have Django – NGINX deployed on your production server follow these simple steps. 1. Install required packages using apt sudo apt install nginx uwsgi uwsgi-plugin-python3 Why do you need uWSGI? In very simple terms NGINX on its own cannot run a Python process to host your application, for this you’ll need a so called application server that will host a Python process running your Django project. NGINX and uWSGI will “talk” each other using the uwsgi protocol. 2. Create directories for your static and media files Static files are “not-python” files needed by your Django project, for example Javascript, CSS and images. Media files will be the files uploaded by the users of your application. Not every application will let users upload files, but it’s a very common scenario. Django will not serve static and media files by itself. We’ll leverage NGINX to serve them. First of all you have to create the directories. Here I assume that you are … -
Django NGINX: deploy your Django project on a production server
Django NGINX is a popular and well tested combination used to deploy web applications in production. In this post I will explain the steps needed to have your Django project deployed on a production server using Ubuntu 18.04. To have Django NGINX deployed on your production server follow these simple steps. Table of Contents Django Nginx: it's better together! Install required packages using apt Create directories for your static and media files Setup your Django project and install requirements Collect static files Configure uWSGI to host your Django project Configure NGINX to serve your application Enjoy your Django NGINX application Extra step: automate all these steps with Ansible! Django Nginx: it's better together! Django is a web framework written in Python. It lets you develop and prototype web applications with little effort. It comes with many built-in features that are often useful in a web application, such as: session management, user authentication, an object relational mapper, a template language. NGINX is a very fast and configurable web server that is very well suited to serve static files and act as a reverse proxy for other applications. In this tutorial I'll explain how to configure NGINX to serve static files (images, … -
Django DetailView - podstawowy widok generyczny
DetailView w Django to podstawowy widok generyczny. Poznaj go koniecznie! -
My Python Development Environment, 2020 Edition
For years I’ve noodled around with various setups for a Python development environment. A couple of years ago I wrote about a setup I finally liked; this is an update to that post. Bad news: this stuff still isn’t stable, and I’ve had to make some changes. Good news: the general concepts still hold, and the new tools a generally a bit better. If you’re curious about the changes and why I made them, there’s a section at the very end about that. -
Full Text Search in Django
A detailed post describing how to implement search in Django. -
Full Text Search in Django
A detailed post describing how to implement search in Django. -
Full Text Search Django
A detailed post describing how to implement search in Django. Today we are going to be talking about Full Text Search in Django. Now even though Django is a batteries included web framework, it does not come with an inbuilt search functionality, there isn’t one perfect way to implement search in your web application provided by it, there are many different ways in which it can be done, today we are gonna be talking about a few of those methods, let’s start by first listing out the methods which we can utilise, I will be giving you a brief overview of each method as well: Basic : When you have a small scale app and you just wanna implement a search view that can be used to filter out the items based on user’s query without any added intelligence, you can utilise the filter function provided within the Django ORM itself, or there’s another thing called Q object present in it, which you can use for that purpose as well. We’ll discuss the two in the subsequent sections. Full Text Search : Django provides Full Text Search ability included in the django.contrib.postgres module, now going by its name you must … -
Random, Fixed Ordering and Pagination
Consider the following situation: > We have a set of items that we want to show in a random order. > The order, however, should remain fixed for a period. > The display of items will need to be paginated, and we have over 200,000 items. If the ordering is not truly random, then we could have an expression index, and allow ordering based on that. However, that doesn't really help out with the pagination, and issues around LIMIT/OFFSET ordering of very large sets. Instead, I came up with a solution this afternoon that uses Postgres Materialised Views. Let's start with a Django model: {% highlight python %} class Post(models.Model): title = models.TextField() content = models.TextField() posted_at = models.DateTimeField() {% endhighlight %} We can build up a materialised view that associates each post with a position: {% highlight postgresql %} CREATE MATERIALISED VIEW post_ordering AS SELECT post.id AS post_id, row_number() OVER () AS position FROM ( SELECT id FROM blog_post ORDER BY random() ) post; CREATE INDEX post_ordering_id ON post_ordering(post_id); CREATE INDEX post_ordering_position ON post_ordering(position); {% endhighlight %} Because a materialised view stores a copy of the data, we need to index it if we want to get performance benefits. … -
Channels
Weekly Django Chat newsletterdjango-channelsDjangoCon 2019 - Just Add Await: Retrofitting Async Into Django by Andrew GodwinDeveloping a Real-Time Taxi App with Django Channels and Angularhttpxdeps: Django Enhancement ProposalsDjango Developers Google GroupDjango Forum -
Start Learning Web Development
There is a LOT of good information out there. Tutorials, videos, paid courses, free courses… so much good stuff. When I decided I wanted to learn to code,…