Django community: Community blog posts RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
A Complete Beginner's Guide to Django - Part 1
Introduction I’m starting today a new tutorial series about the Django fundamentals. It’s a complete beginner’s guide to start learning Django. The material is divided in 7 parts. We’re going to explore all the basic concepts in great detail, from installation, preparation of the development environment, models, views, templates, urls to more advanced topics such as migrations, testing and deployment. I wanted to do something different. A tutorial that would be easy to follow, informative and fun to read. That was when I came up with the idea to create some comics along the text to illustrate some concepts and scenarios. I hope you enjoy the reading! But before we start… Back when I worked as a substitute professor in a university, I used to teach a introduction to web development discipline for the newcomer students in the Computer Science course. And I would always start a new classes with this Confucius quote: So, hands on! Don’t just read the tutorials. Let’s do it together! You will learn much more by doing and practicing. Installation The first thing we need to do is install some programs in our machine so to be able to start playing with Django. The basic … -
Moving to Relay in Django backend
Today I want to talk a little bit more about my next step in developing a GraphQL application. This step is connected with moving backend so it understands Relay. What exactly is Realy? As documentation of Relay suggests - it's framework for working with external data in React. What does it … -
Going to Technical Events is Awesome: A DjangoCon Experience
We just got back from DjangoCon US! It was quite a marathon for us, as you can check here and yet quite fruitful. Along with the talks we got to give, it was awesome to meet new people and reunite with old friends. From our blog, you’d guess that we really enjoy conferences. We incentivize collaborators to attend them. Attending conferences is a gr -
Going to Technical Events Can be Awesome: A DjangoCon Experience
Going to Technical Events Can be Awesome: A DjangoCon Experience -
How going to technical events can be awesome: A DjangoCon Experience
-
post-DjangoCon US
-
Advanced Django File Handling
Advanced Django File Handling Modern Django's file handling capabilities go well beyond what's covered in the tutorial. By customizing the handlers that Django uses, you can do things pretty much any way you want. Static versus media files Django divides the files your web site is serving unchanged (as opposed to content delivered by your Django views) into two types. "Static" files are files provided by you, the website developer. For example, these could be JavaScript and CSS files, HTML files for static pages, image and font files used to make your pages look nicer, sample files for users to download, etc. Static files are often stored in your version control system alongside your code. "Media" files are files provided by users of the site, uploaded to and stored by the site, and possibly later served to site users. These can include uploaded pictures, avatars, user files, etc. These files don't exist until users start using the site. Two jobs of a Django storage class Both kinds of files are managed by code in Django storage classes. By configuring Django to use different storage classes, you can change how the files are managed. A storage class has two jobs: Accept … -
Renaming Django's Auth User and App
Now that Evennia's devel branch (what will become Evennia 0.7) is slowly approaching completion, I thought I'd try to document an aspect of it that probably took me the longest to figure out. One change in Evennia 0.7 is that the Django model named "Player" changes name to "Account". Over time it has become clear that the old name didn't properly reflected the intention of the model. Sounds like a simple change, right? Well, it was not.Briefly on migrationsFirst some background. A Django migration is a small Python file sitting in migrations/ sub folders throughout Evennia. A migration describes how our database schema changes over time, so as we change or update fields or add new features we add new migrations to describe how to go from the old to the new state. You apply them with the `evennia migrate` command we sometimes ask you to run. If we did not supply migrations, anyone with an existing Evennia database would have to either start from scratch or manually go in and tweak their database to match every upstream change we did.Each migration file has a sequential number, like migration_name.0002.py etc. Migrations will run in order but each migration can also … -
What are Kubernetes Pods Anyway?
Recently I saw a tweet from the awesome Amy Codes (I really hope that's her real name) about Kubernetes Pods: > You know why containers in a pod are always scheduled together? It's cuz they're nested containers. Mind. Blown. > > -- Amy Codes (@TheAmyCode) August 21, 2017 While it wasn't 100% accurate (Containers aren't really a thing. We'll get to that in a bit) it did point out the fact that Pods are amazing things. It's worth taking a look at Pods and containers in general and learn what they actually are. The Kubernetes documentation on Pods provides the best and most complete[...] -
What are Kubernetes Pods Anyway?
Recently I saw a tweet from the awesome Amy Codes (I really hope that's her real name) about Kubernetes Pods: > You know why containers in a pod are always scheduled together? It's cuz > they're nested containers. > > Mind. Blown. > > -- Amy Codes (@TheAmyCode) August 21, 2017 While it wasn't 100% accurate (Containers aren't really a thing. We'll get to that in a bit) it did point out the fact that Pods are amazing things. It's worth taking a look at Pods and containers in general and learn what they actually are. The Kubernetes documentation on Pods provides the best and most comp[...] -
Silvrback Rolls Out New Look
-
DjangoCon 2017 Recap
Mid-August brought travel to Spokane for several Caktus staff members attending DjangoCon 2017. As a Django shop, we were proud to sponsor and attend the event for the eighth year. Meeting and Greeting We always look forward to booth time as an opportunity to catch up with fellow Djangonauts and make new connections. Caktus was represented by a team of six this year: Charlotte M, Karen, Mark, Julie, Tobias, and Whitney. We also had new swag and a GoPro Session to give away. Our lucky winner was Vicky. Congratulations! This year we also had a special giveaway: one free ticket to the conference, donated to DjangoGirls Spokane. The winner, Toya, attended DjangoCon for the first time. We hope she had fun! Toya's a lucky #djangogirl. She won a ticket to @djangocon from @CaktusGroup and a book from keynote speaker @limedaring 🦄 pic.twitter.com/LxvSxPjW0S— Django Girls Spokane (@DjangoGirlsSpo) August 12, 2017 Top Talks Our technical staff learned a lot from attending the other talks presented during the conference. Their favorite talks included the keynote by Alicia Carr, The Denormalized Query Engine Design Pattern, and The Power and Responsibility of Unicode Adoption. Awesome inspiring keynote by @Fineblkwoman about how you can learn to … -
CFE CLI
The Coding for Entrepreneurs C... -
Updates to Love
-
How to Use Celery and RabbitMQ with Django
Celery is an asynchronous task queue based on distributed message passing. Task queues are used as a strategy to distribute the workload between threads/machines. In this tutorial I will explain how to install and setup Celery + RabbitMQ to execute asynchronous in a Django application. To work with Celery, we also need to install RabbitMQ because Celery requires an external solution to send and receive messages. Those solutions are called message brokers. Currently, Celery supports RabbitMQ, Redis, and Amazon SQS as message broker solutions. Table of Contents Why Should I Use Celery? Installation Installing RabbitMQ on Ubuntu 16.04 Installing RabbitMQ on Mac Installing RabbitMQ on Windows and Other OSs Celery Basic Setup Creating Our First Celery Task Starting The Worker Process Managing The Worker Process in Production with Supervisord Further Reading Why Should I Use Celery? Web applications works with request and response cycles. When the user access a certain URL of your application the Web browser send a request to your server. Django receive this request and do something with it. Usually it involves executing queries in the database, processing data. While Django does his thing and process the request, the user have to wait. When Django finalize its … -
Monorepo structure for Django & React Applications
Hello! Today I will guide you through setting up React application with Django! Let's get started! First thing is where I place my javascript application? Should it be in another repository? Or maybe Django should use webpack to render js? I decided to use pattern called monorepo. What does it … -
How to Render Django Form Manually
Dealing with user input is a very common task in any Web application or Web site. The standard way to do it is through HTML forms, where the user input some data, submit it to the server, and then the server does something with it. Now, the chances are that you might have already heard that quote: “All input is evil!” I don’t know who said that first, but it was very well said. Truth is, every input in your application is a door, a potential attack vector. So you better secure all doors! To make your life easier, and to give you some peace of mind, Django offers a very rich, reliable and secure forms API. And you should definitely use it, no matter how simple your HTML form is. Managing user input, form processing is a fairly complex task, because it involves interacting with many layers of your application. It have to access the database; clean, validate, transform, and guarantee the integrity of the data; sometimes it needs to interact with multiple models, communicate human readable error messages, and then finally it also have to translate all the Python code that represents your models into HTML inputs. In … -
Demystifying encodings — part 2
As we saw in part 1 of this series, each program reads stuff from input and writes stuff to output. Whenever it reads strings of characters in the input, these strings are encoded in a certain encoding such as UTF-8. The program must decode these strings into an internal representation. When writing to the output, the program encodes strings from its internal representation to an encoding such as UTF-8. What this internal representation is is usually not our concern. For example, in Python versions earlier than 3.3, the internal representation is either UCS-2 or UCS-4, depending on how Python was compiled. In Python 3.3 or later, the internal representation is more complicated and described in PEP 393. But these details are rarely of interest; what matters is that a program must be able to communicate with other programs via its input/output, and for this to work properly the programs must agree on an external representation. Whenever you see “appétit” rendered as “appétit” it usually means that two programs did not agree on the encoding of the external representation; for example, that one program sent UTF-8 to its output, and another program read this output as its input, thinking it was … -
Django Patterns: Fat Models and `cached_property`
One of my favorite patterns in Django is the combination of "fat" models and cached_property from django.utils.functional. Fat models are a general MVC concept which encourages pushing logic into methods on your Model layer rather than the Controller ("view" in Django parlance). This has a lot of benefits. It helps maintain the DRY (Don't Repeat Yourself) principle by making common logic easy to find/reuse and makes it easy to break the logic down into small testable units. One problem with this approach is that as you break down your logic into smaller more reusable units, you may find yourself using them multiple times within a single response. If your methods are particularly resource intensive, it will become an unnecessary performance hit. A common place you find this is in Django tempaltes with patterns like this: {% if item.top_ten_reviews %} <ul> {% for review in item.top_ten_reviews %} ... This will call the top_ten_reviews method twice. If that method is making database calls, you've now doubled them. Enter cached_property. This decorator will cache the results of a method for the duration of the request and return it as a property when called again. This technique is known as memoization. Let's look at … -
Django Patterns: Fat Models and cached_property
One of my favorite patterns in Django is the combination of "fat" models and cached_property from django.utils.functional. Fat models are a general MVC concept which encourages pushing logic into methods on your Model layer rather than the Controller ("view" in Django parlance). This has a lot of benefits. It helps maintain the DRY (Don't Repeat Yourself) principle by making common logic easy to find/reuse and makes it easy to break the logic down into small testable units. One problem with this approach is that as you break down your logic into smaller more reusable units, you may find yourself using them multiple times within a single response. If your methods are particularly resource intensive, it will become an unnecessary performance hit. A common place you find this is in Django templates with patterns like this: {% if item.top_ten_reviews %} <ul> {% for review in item.top_ten_reviews %} ... This will call the top_ten_reviews method twice. If that method is making database calls, you've now doubled them. Enter cached_property. This decorator will cache the results of a method for the duration of the request and return it as a property when called again. This technique is known as memoization. Let's look at … -
Large File Uploads with Amazon S3 + Django
****In Development**** This... -
ShipIt Day Recap Q3 2017
Caktus recently held the Q3 2017 ShipIt Day. Each quarter, employees take a step back from business as usual and take advantage of time to work on personal projects or otherwise develop skills. This quarter, we enjoyed fresh crêpes while working on a variety of projects, from coloring books to Alexa skills. Technology for Linguistics As both a linguist and a developer, Neil looked at using language technology for a larger project led by Western Carolina University to revitalize Cherokee. This polysynthetic language presents challenges for programming due to its complex word structure. Using finite state morphology with hfst and Giellatekno, Neil explored defining sounds, a lexicon, and rules to develop a model. In the end, he feels a new framework could help support linguists, and says that Caktus has shown him the value of frameworks and good tooling that could be put to use for this purpose. Front-end Style Guide Primer Although design isn’t optional in product development, the Agile methodology doesn’t address user interface (UI) or user experience (UX) design. We use Agile at Caktus, but we also believe in the importance of solid UX in our projects. Basia, Calvin, and Kia worked to fill the gap. They … -
Django Tips #21 Using The Redirects App
Django comes with a few optional apps that can easily be installed. One of those apps is the Redirects App, which is particularly useful in the cases where you want to update some existing URLs without compromising your Website SEO or in any case avoid 404 errors. It basically works by creating a table in the database with two columns, old_path and new_path. Every time your Website raises a 404 error, the Redirects App will intercept the response and check this particular table for a match. If the requested URL is found in the column old_path, instead of raising the 404 error, it will redirect the user to the new_path returning a 301 code (Moved Permanently). Alright, so let’s see how it works in practice. Installation The Django Redirects App requires the sites framework to be installed. You can install them by adding the apps to your project’s INSTALLED_APPS: settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'django.contrib.redirects', ] Set a SITE_ID so the sites framework works properly. settings.py SITE_ID = 1 Now, add the redirects middleware to the MIDDLEWARE configuration: settings.py MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.contrib.redirects.middleware.RedirectFallbackMiddleware', ] Make sure you … -
Make Django Rest Framework and Axios Work Together Nicely
This is a solution to the problem I encountered while marrying Django Rest Framework powered API and Axios JS HTTP client: Axios issues GET requests with multi-value parameters in a bit different way than Django expects. When you create your API with Django Rest Framework, it expects multi-value GET parameters ... Read now -
A Minimal Django Application
In this article I want to explore some of the basic concepts of Django, setting up a minimal web application to get a deeper understanding of how Django works under the hoods. An important disclaimer before we start, that’s not a tutorial about how to start a Django application, it’s more of an exploratory experiment for learning purpose. Introduction If you are reading this article, the chances are that you already know that Django is a Web framework written in Python. But that’s an abstract definition. In practice, Django is a Python package that lives inside the site-packages directory of your current Python installation. That means it lives alongside with other Python packages, such as Requests, Pillow and NumPy. A simple way to verify a Django installation is importing it in a Python shell: >>> import django >>> print(django.get_version()) 1.11.4 But the way we interact with Django is a little bit different than the way we interact with other Python packages. Usually we don’t import it directly into our Python programs to make use of its resources. When we first start learning Django, we are taught that we should start a new project using the django-admin command-line utility by executing …