Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
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. 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 … -
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,… -
Start Learning Web Development
Skip to tl;dr 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, I just started doing whatever looked interesting to me. It’s easy to fall into the trap of trying to pick the “optimal” syllabus for your personal learning journey. I wanted to start coding now. I actually started years ago – overnight in an airport in Bergen, Norway – doing the Django polls tutorial. This is a good one, but my goodness it was a hard time. Yes, we can attribute that partially to pulling an all-nighter. I definitely get dumber without sleep. But the real problem was that I just didn’t understand much of anything about web development. Plus, my Python was meh at best. The Django polls tutorial is good, but probably not where you want to start. First, learn Python I found that whole experience kind of frustrating. I made it through the whole app, but I didn’t know any programming and didn’t really understand how this web development framework even works. I didn’t understand any of the anatomy – the structure – of the code, so … -
To •••• With Passwords
Slides Video Notes THREAD: some marginalia and further reading for folks who attended my #nbpy talk and would like to explore further 👇🏻 — jacobian (@jacobian) November 2, 2019 -
Functions as Tables in Django and Postgres
Postgres has some excellent features. One of these is [set-returning functions](https://www.postgresql.org/docs/current/functions-srf.html). It's possible to have a function (written in SQL, or some other language) that returns a set of values. For instance, the in-built function `generate_series()` returns a set of values: {% highlight sql %} SELECT day::DATE FROM generate_series(now(), now() + INTERVAL '1 month', '1 day') day; {% endhighlight %} This uses a set returning function as a table source: in this case a single column table. You can use scalar set-returning functions from within Django relatively easily: [I blogged about it last year](https://schinckel.net/2018/11/02/set-returning-and-row-accepting-functions-in-django-and-postgres/). It is possible to [create your own set-returning functions](https://www.postgresql.org/docs/current/sql-createfunction.html). Further, the return type can be a `SETOF` any table type in your database, or even a "new" table. {% highlight postgresql %} CREATE OR REPLACE FUNCTION foo(INTEGER, INTEGER) RETURNS TABLE(id INTEGER, bar_id INTEGER, baz JSON[]) AS $$ SELECT foo.id AS id, bar.id AS bar_id, ARRAY_AGG(JSON_BUILD_OBJECT(bar.x, foo.y)) FROM foo INNER JOIN bar ON (foo.id = bar.foo_id) WHERE foo.y = $1 AND bar.x > $2 GROUP BY foo.id, bar.id $$ LANGUAGE SQL STABLE; {% endhighlight %} It's possible to have a Postgres VIEW as the data source for a Django model (you just set the `Meta.db_table` on the … -
Django Slug Tutorial
How to add slugs to a Django DetailView. -
How Django Experts Think
Carlton’s Python bugPython 3 Standard LibraryBest Python booksDjango for ProfessionalsDreyfus Model of Skill AcquisitionZen Mind, Beginner’s Mind book -
How to deploy Django project to Dokku
In this Dokku tutorial, I will talk about how to deploy Django project with Dokku, it would use Postgres db and Amazon S3 to store data and media files. -
How to make Django request.is_ajax() work with JS fetch()
Django's request object has a nifty little method is_ajax. It allows determining whether a request comes from a JS framework (aka old-school ajax). While it works fine with some JS libraries, including the venerable jQuery, it won't work out of the box with modern JS native fetch API ... Read now -
Detecting queries in Django tests
Putting this here so I can find it next time I need to know it... Django has a useful test assertion you can use to ensure you make a set number of queries. However, at times this is a bit less useful than it needs to be, because something changes and we do indeed have a different number of queries, but it's got nothing to do with the actual code under test. If you are running in `DEBUG=True` mode, then you can examine the queries that have been made to the database connection, and ensure the raw SQL of a specific query matches (and is not duplicated, for instance). This does require a little bit of trickery: {% highlight python %} from django.db import connection from django.test import TestCase, override_settings from foo.factories import FooFactory class TestTheThing(TestCase): def test_no_update_query(self): foo = FooFactory() # Our Foo instance should be smart enough to notice that nothing # has changed, and thus should not emit an UPDATE query. with override_settings(DEBUG=True): foo.save() self.assertFalse([ x for x in connection.queries if 'UPDATE' in x['sql'] ]) {% endhighlight %} This is a bit of a contrived case: in my case today it was a celery task that only … -
Things I want to remember about SSH
SSH, short for Secure Shell, is a protocol for secure network communications. It is widely used for executing commands on remote servers, and for file uploads or downloads. If you are working with Django, use Git version control, or administrate servers, you surely are using SSH. In this post, I want to share some technical details about it. Secure Shell is using private and public key pairs. You can either use automatically generated private and public keys combined with a password, or manually generated private and public keys. In the latter case, you need to keep your private key on your computer and upload the public key to the remote server. Creating a pair of SSH keys manually If you are using GitHub, Bitbucket, DigitalOcean, or some other service, you might have seen the possibility to upload public SSH keys for direct access to remote servers. Here is how you usually create the SSH keys on the computer from which you want to establish a secure connection (your local machine or one of your servers that has access to other servers or services). In the Terminal you would execute these commands: $ ssh-keygen$ ssh-agent /usr/local/bin/bash$ ssh-add ~/.ssh/id_rsa The id_rsa is … -
Middleware
Weekly Django Chat newsletterMiddleware in Django DocsCarlton's DjangoCon US 2019 talk on Django as a MicroframeworkWSGIBaseHandler class in Django source code