Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Django File (and Image) Uploads Tutorial
Learn how to add user-uploaded files and images to a Django project. -
Mercurial Mirror For Django 2.1 Branch
I’m slightly late on this one, but here it is. For the record, main purposes of this mirror are: being a lightweight read-only repository to clone from for production servers hide the ugly git stuff behind a great mercurial interface The clone is at the usual location at bitbucket, from which you can browse, clone, […] -
Django Tips #8: Projects vs Apps
An explanation of Django structure and what constitutes an "app." -
An Introduction to Designing for Virtual Reality: 5 Lessons to Help You Get Started
Test driving a luxury car from the comfort of your couch. Getting on a rollercoaster that careens you through a world seething with fire-breathing dragons. Experiencing a spacewalk just as an astronaut would, floating 250 feet above the Earth. Today, these otherwise unimaginable experiences are all possible in virtual reality. The post An Introduction to Designing for Virtual Reality: 5 Lessons to Help You Get Started appeared first on Distillery. -
Equivalents in Python and JavaScript. Bonus
From time to time I google for the right syntax how to process lists and dictionaries in Python or arrays and objects in JavaScript. So I decided to extend my series of equivalents with those functions. After all, it's me too, who will be using the information I provide here. All truthful elements Sometimes we need to check from a list of conditions if all of them are true, or from a list of elements if all of them are not empty. This can be checked with the following in Python: items = [1, 2, 3]all_truthy = all(items)# True And here is an equivalent in JavaScript: items = [1, 2, 3];all_truthy = items.every(Boolean);// true Any truthful elements Similarly, we can check if at least one of the conditions is true, or there is at least one non-empty element in a list. It Python we would do that with: items = [0, 1, 2, 3]some_truthy = any(items)# True And in JavaScript we would check it like this: items = [0, 1, 2, 3];some_truthy = items.some(Boolean);// true Iterate through each element and its index Here is an example of how to iterate through a list of items and also check their indices … -
Equivalents in Python and JavaScript. Bonus
From time to time I google for the right syntax how to process lists and dictionaries in Python or arrays and objects in JavaScript. So I decided to extend my series of equivalents with those functions. After all, it's me too, who will be using the information I provide here. All truthful elements Sometimes we need to check from a list of conditions if all of them are true, or from a list of elements if all of them are not empty. This can be checked with the following in Python: items = [1, 2, 3] all_truthy = all(items) # True And here is an equivalent in JavaScript: items = [1, 2, 3]; all_truthy = items.every(Boolean); // true Any truthful elements Similarly, we can check if at least one of the conditions is true, or there is at least one non-empty element in a list. It Python we would do that with: items = [0, 1, 2, 3] some_truthy = any(items) # True And in JavaScript we would check it like this: items = [0, 1, 2, 3]; some_truthy = items.some(Boolean); // true Iterate through each element and its index Here is an example of how to iterate through a … -
A Guide To Creating An API Endpoint With Django Rest Framework
As part of our work to make sharp web apps at Caktus, we frequently create API endpoints that allow other software to interact with a server. Oftentimes this means using a frontend app (React, Vue, or Angular), though it could also mean connecting some other piece of software to interact with a server. A lot of our API endpoints, across projects, end up functioning in similar ways, so we have become efficient at writing them, and this blog post gives an example of how to do so. First, a few resources: read more about API endpoints in this previous blog post and review documentation on Django Rest Framework. A typical request for an API endpoint may be something like: 'the front end app needs to be able to read, create, and update companies through the API'. Here is a summary of creating a model, a serializer, and a view for such a scenario, including tests for each part: Part 1: Model For this example, we’ll assume that a Company model doesn’t currently exist in Django, so we will create one with some basic fields: # models.py from django.db import models class Company(models.Model): name = models.CharField(max_length=255) description = models.TextField(blank=True) website = … -
How to test Django with LiveServerTestCase
When it comes to backend my tools of choice are Django and Python. Speed of development (particulary useful for rapid prototyping) and the excellent test coverage I can get almost out of the box are the major boons for me. I use Django for training aspiring developers too and when I run a workshop I don't go straight to the "right implementation". What I like instead is guiding newcomers through the initial "working implementation" to refactoring into a more complex application. In this tutorial you'll build a small application with the exact same mindset. We'll make it work first and them we will refactor for adding more features. How to test a Django application: what you will learn In the following tutorial you'll learn: how to build a simple Django website how to test a Django application how to measure test coverage How to test a Django application: requirements To follow along with the tutorial you should have: a basic understanding of Python and Django a newer version of Python installed on your system (Python 3 is nice to have) a basic understanding of both unit testing and functional testing How to test a Django application: setting up a Python … -
Implementation of single sign on using auth0 in django application
As the no of applications increases, users need to create username & passwords, need to remember for each application. Users can't remember these details and, sometimes users use single username/password for all applications, then there may be a chance of hacking your accounts easily. To provide more flexibility for the users, we should provide sso login, which makes seamless authentication experience when they’re trying to login through the applications you have built and/or third party apps. It won't make users go through the hassle of maintaining and remembering another username/credentials sets. In this blog post, we’ll see how to add single sign on & single sign out for a django application using auth0. Steps to follow for an auth0 account: Create your account in auth0 Go to applications & click on create application by proving app name(for ex: demoapp) & application type(web or mobile app etc.) Go to settings tab of your application(demoapp), you can see client id, client secret, domain values. Add application domains with a comma separated list in Allowed Web Origins & Allowed Origins (CORS) tab For ex: http://demoapp.io, http://demoauth.io By Default, application will use Username Password authentication database. We can also use custom database based on … -
Voice Tech 101: Everything You Need to Know About Voice User Interface
Interface design enables humans to interact with technology. Excitingly, voice user interfaces are fundamentally changing how we interact with many of our devices. Whether you’re new to voice technology or you’ve already gotten your feet wet, this “everything you need to know” primer gives a high-level overview of the various benefits and challenges of voice. These benefits and challenges will be driving forces in shaping the future of voice user interfaces. To get started, however, let’s first examine how voice interface design is different — and why that’s revolutionary. The post Voice Tech 101: Everything You Need to Know About Voice User Interface appeared first on Distillery. -
Make Django's collectstatic command forgiving
Have this ever happened to you, you run a python manage.py collecstatic command, it progresses for some time and then throws an error, something like ValueError: The file 'theme/startup/css/font/ytp-regular.eot' could not be found with <django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at 0x10b47cc50>? Well, that ... Read now -
7 Conferences We’re Looking Forward To
Above: The Internet Summit in Raleigh is one of the local conferences we recommend attending. (Photo by Ian Huckabee.) At Caktus, we strongly believe in professional development and continued learning. We encourage our talented team to stay up to date with industry trends and technologies. During 2018, Cakti attended a number of conferences around the country. Below is a list (in alphabetical order) of the ones we found the most helpful, practical, and interesting. We look forward to attending these conferences again, and if you get the chance, we highly recommend that you check them out as well. All Things Open Recommended by Account Executive Tim Scales Next Conference Location: Raleigh Next Conference Date: October 13 - 15, 2019 All Things Open is a celebration and exploration of open source technology and its impact. Topics range from nuts and bolts sessions on database design and OSS languages to higher-level explorations of current trends like machine learning with Python and practical blockchain applications. The annual conference is heavily publicized in the open source community, of which Caktus is an active member. All Things Open attracts open source thought leaders from across industries, and it’s a valuable learning experience for both non-technical … -
Container Runtimes Part 4: Kubernetes Container Runtimes & CRI
This is the fourth and last part in a four part series on container runtimes. It's been a while since part 1, but in that post I gave an overview of container runtimes and discussed the differences between low-level and high- level runtimes. In part 2 I went into detail on low-level container runtimes and built a simple low-level runtime. In part 3 I went up the stack and wrote about high-level container runtimes. Kubernetes runtimes are high-level container runtimes that support the Container Runtime Interface (CRI). CRI was introduced in Kubernetes 1.5 and acts as a bridge between the [...] -
Container Runtimes Part 4: Kubernetes Container Runtimes & CRI
This is the fourth and last part in a four part series on container runtimes. It's been a while since part 1, but in that post I gave an overview of container runtimes and discussed the differences between low-level and high- level runtimes. In part 2 I went into detail on low-level container runtimes and built a simple low-level runtime. In part 3 I went up the stack and wrote about high-level container runtimes. Kubernetes runtimes are high-level container runtimes that support the Container Runtime Interface (CRI). CRI was introduced in Kubernetes 1.5 and acts as a bridge between the [...] -
Django Quiz 2016
I realized I’ve posted the 2017 and 2018 editions of the London Django Meetup December quizzes on my blog, but forgot to post the first one in 2016. So here it is reproduced below, if you’d like to play at home or scroll through to the answers to pick up on some more Django trivia. Part 1: Multiple Choice 1. In which city in Kansas was Django conceived? Newton Lawrence Pittsburg 2. In what year was Django first released? 1999 2001 2005 3. Where was Djangocon EU 2016 held? Cardiff Budapest Bucharest 4. When does Python 2.7 stop being supported? 1 Jan 2018 2020 April 12 2020 5. Which version of Django will drop Python 2 compatibility? 1.12 2.0 2.1 6. Which of these popular sites does not run on Django? Instagram Slideshare Bitbucket Disqus 7. What is i18n short for? Internationalization International Code 18 Internal operation 8. Which official Django project offers websocket and asynchronous task support? Inputs Transmissions Channels 9. What does SQL stand for? Standard Query Language Structured Query Language SQL’s a Query Language Part 2: Freeform answers 1. Which database servers does Django core include backends for? One point each, but minus one for each wrong. … -
How to add buttons to ModelAdmin Index View in Wagtail CMS
By default, every object in ModelAdmin's Index View of Wagtail CMS gets two buttons: Edit and Delete. What if we want to add more buttons? Is that possible in Wagtail? My answer is yes, and it's easy! Follow me! Let's add a "View" button Let's assume ... Read now -
Dagger 2: How to Understand and Use Components and Modules
Dagger is a great tool for dependency injection (DI). It does most of the job in compile time, making applications smaller and faster and dependency resolving safer. The post Dagger 2: How to Understand and Use Components and Modules appeared first on Distillery. -
variable_cache_control - Django view decorator to set max_age in runtime
tl;dr; If you use the django.views.decorators.cache.cache_control decorator, consider this one instead to change the max_age depending on the request. I had/have a Django view function that looks something like this: @cache_control(publiic=True, max_age=60 * 60) def home(request, oc=None, page=1): ... But, that number 60 * 60 I really needed it to be different depending on the request parameters. For example, that oc=None, if that's not None I know the page's Cache-Control header can and should be different. So I wrote this decorator: from django.utils.cache import patch_cache_control def variable_cache_control(**kwargs): """Same as django.views.decorators.cache.cache_control except this one will allow the `max_age` parameter be a callable. """ def _cache_controller(viewfunc): @functools.wraps(viewfunc) def _cache_controlled(request, *args, **kw): response = viewfunc(request, *args, **kw) copied = kwargs if kwargs.get("max_age") and callable(kwargs["max_age"]): max_age = kwargs["max_age"](request, *args, **kw) # Can't re-use, have to create a shallow clone. copied = dict(kwargs, max_age=max_age) patch_cache_control(response, **copied) return response return _cache_controlled return _cache_controller Now, I can do this instead: def _best_max_age(req, oc=None, **kwargs): max_age = 60 * 60 if oc: max_age *= 10 return max_age @variable_cache_control(publiic=True, max_age=_best_max_age) def home(request, oc=None, page=1): ... I hope it inspires. -
PyRoma 2019
The first of the PyRoma (Python User Group of Rome, Italy) periodic meetings in 2019 -
A Salmagundi of Django Alpha Announcements
Reading the Django 2.2 alpha announcement, the phrase “salmagundi of new features” stood out to me. I had to look up “salmagundi” in Wiktionary, where it is defined as: A food consisting of chopped meat and pickled herring, with oil, vinegar, pepper, and onions. Hence, any mixture of various ingredients; an olio or medley; a potpourri; a miscellany. So it basically means there is a mix of new features. This reminded me, didn’t Django 2.1 use another food related word for this - “smorgasboard”? Looking back at the previous alpha announcements, it turns out that a plethora of words have been used to describe the variety of features offered by each release. It seems the tradition started with version 1.7 - the 1.6 alpha announcement post refers simply to “new stuff”. I pulled the phrases, the individual “mix” words, and the post authors for all the announcement posts back to 1.7. I then checked the words against the word frequency list Peter Norvig provides in his article English Letter Frequency Counts, based upon Google Books data of the millions of English books Google have scanned. For reference, the most common word there is “the” with a frequency of 53,097,401,461 (see … -
The Future of Typography: An Introduction to Variable Fonts
Designers, imagine a world in which the number of fonts used on a website or app isn’t limited by load speed, or by the availability of styles in a font family. You’d no longer be limited to a few weights (light, regular, bold) and widths (condensed, regular, expanded). Instead, you could exercise a fine degree of control over all of these properties. The post The Future of Typography: An Introduction to Variable Fonts appeared first on Distillery. -
How to Dockerize Django and Postgres
Docker is an invaluable tool that makes things like setting up your local development environment, continuous integration, and deployment a breeze. Docker is good to set up early on for any application, but it is never too late. With the help of Docker Compose, we are going to set up a Django application to install … Continue reading How to Dockerize Django and Postgres The post How to Dockerize Django and Postgres appeared first on concise coder. -
How to Dockerize Django and Postgres
Docker is an invaluable tool that makes things like setting up your local development environment, continuous integration, and deployment a breeze. Docker is good to set up early on for any application, but it is never too late. With the help of Docker Compose, we are going to set up a Django application to install … Continue reading How to Dockerize Django and Postgres The post How to Dockerize Django and Postgres appeared first on concise coder. -
How to Create PDF Documents with Django in 2019
If you've read my Web Development with Django Cookbook, you might remember a recipe for creating PDF documents using Pisa xhtml2pdf. Well, this library does its job, but it supports only a subset of HTML and CSS features. For example, for multi-column layouts, you have to use tables, like it's 1994. I needed some fresh and flexible option to generate donation receipts for the donation platform www.make-impact.org and reports for the strategic planner 1st things 1st I have been building. After a quick research I found another much more suitable library. It's called WeasyPrint. In this article, I will tell you how to use it with Django and what's valuable in it. Features WeasyPrint uses HTML and CSS 2.1 to create pixel-perfect, or let's rather say point-perfect, PDF documents. WeasyPrint doesn't use WebKit or Gecko but has its own rendering engine. As a proof that it works correctly, it passes the famous among web developers Acid2 test which was created back in the days before HTML5 to check how compatible browsers are with CSS 2 standards. All supported features and unsupported exceptions are listed in the documentation. But my absolute favorites are these: Layouts with floated elements. You don't have … -
How to Create PDF Documents with Django in 2019
If you've read my Web Development with Django Cookbook, you might remember a recipe for creating PDF documents using Pisa xhtml2pdf. Well, this library does its job, but it supports only a subset of HTML and CSS features. For example, for multi-column layouts, you have to use tables, like it's 1994. I needed some fresh and flexible option to generate donation receipts for the donation platform www.make-impact.org and reports for the strategic planner 1st things 1st I have been building. After a quick research I found another much more suitable library. It's called WeasyPrint. In this article, I will tell you how to use it with Django and what's valuable in it. Features WeasyPrint uses HTML and CSS 2.1 to create pixel-perfect, or let's rather say point-perfect, PDF documents. WeasyPrint doesn't use WebKit or Gecko but has its own rendering engine. As a proof that it works correctly, it passes the famous among web developers Acid2 test which was created back in the days before HTML5 to check how compatible browsers are with CSS 2 standards. All supported features (and unsupported exceptions) are listed in the documentation. But my absolute favorites are these: Layouts with floated elements. You don't have …