Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Security
Weekly DjangoChat NewsletterSecurity in DjangoDjango deployment checklistbleachHTML Escape Tool -
Automate your Telegram channel with a Django Telegram Bot
In this post I will guide you in a very interesting and funny development task: automate your Telegram channel with a Django Telegram Bot. Telegram is a popular instant messaging application. It’s not as widespread as Whatsapp, but its user base is constantly growing and according to Wikipedia: The number of monthly Telegram users as of October 2019 is 300 million people worldwide A very interesting aspect of the Telegram platform is the ability to create channels and bots to automate the broadcasting of messages to large audiences. These features open the possibility to better engage your users using Telegram, for example by sending them news, offers, etc. all from your existing Django web project! Let’s see how to do it. 1. Create a Telegram channel Nothing special here: you can do this from the Telegram app on your phone. Just tap “New Channel” on the Telegram main menu. Choose a name, a description and a nice “permalink” for your channel: 2. Create a Telegram Bot Now the funny part begins: search for a contact named “BotFather” on Telegram This is a bot to manage bots, a sort of meta-bot. 🙂 Start a chat with him and write /help … -
Automate your Telegram channel with a Django Telegram Bot
In this post I will guide you in a very interesting and funny development task: automate your Telegram channel with a Django Telegram Bot. Telegram is a popular instant messaging application. It’s not as widespread as Whatsapp, but its user base is constantly growing and according to Wikipedia: The number of monthly Telegram users as of October 2019 is 300 million people worldwide A very interesting aspect of the Telegram platform is the ability to create channels and bots to automate the broadcasting of messages to large audiences. These features open the possibility to better engage your users using Telegram, for example by sending them news, offers, etc. all from your existing Django web project! Let’s see how to do it. Table of Contents 1. Create a Telegram channel 2. Create a Telegram Bot 3. Make the bot an Admin for your Telegram channel 4. Install python-telegram-bot 5. Edit your Django settings to add Telegram parameters 6. Send a message to the channel from your Django code 7. Conclusions 8. Do you want more power for your Django Telegram bot? 1. Create a Telegram channel Nothing special here: you can do this from the Telegram app on your phone. Just … -
Angular 9 CRUD Tutorial: Consume a Python/Django CRUD REST API
Angular 9 is in pre-release! Read about its new features in this article and how to update to the latest Angular version in this article. You can also get our Angular 8 book for free or pay what you can. This tutorial is designed for developers that want to use Angular 9 to build front-end apps for their back-end REST APIs. You can either use Python & Django as the backend or use JSON-Server to mock the API if you don't want to deal with Python. We'll be showing both ways in this tutorial. Check out the other parts of this tutorial: Adding Routing Building Navigation UI Using Angular Material 8 This tutorial deals with REST APIs and routing but you can also start with basic concepts by following this tutorial (part 1 and part 2) instead which you'll build a simple calculator. If you would like to consume a third-party REST API instead of building your own API, make to check out this tutorial. You will see by example how to build a CRUD REST API with Python. The new features of Angular 9 include better performance and smaller bundles thanks to Ivy. Throughout this tutorial, designed for beginners, … -
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.