Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Single Page Apps with Flask and Angular 4|5 Tutorial Series
In this tutorial series we'll be using Python, Flask, SQLAlchemy and Angular 5 to build a modern RESTful web application with an architecture that consists of a front-end application with Angular 5 and a back-end REST API using Flask. The application we'll be building is a simple CRUD (Create, Read, Update and Delete) system for managing customers. This can be further extended to build a fully featured Customer Management System by implementing more use cases. The first tutorial will cover how to set up both the back-end and front-end applications and how to install the necessary dependencies. Series Tutorials Introduction and Setting Up Flask and Angular (current tutorial) Using the SQLAlchemy ORM to Create Database Models Routing and Navigation with The Angular Router Angular State Management with ngrx Integrating Angular with Flask Building a REST API with Flask Consuming The REST API with Angular HttpClient Adding JWT Authentication Getting Ready for Production and Deployment Before we dive into the practical steps let's briefly go over the technologies we are going to use in this tutorial: Flask: a Python micro-framework for building web applications that's know to be light and scalable. Flask has many features such as: It's easy to setup … -
How to Integrate Highcharts.js with Django
Highcharts is, in my opinion, one of the best JavaScript libraries to work with data visualization and charts out there. Even though Highcharts is open source, it’s a commercial library. It’s free for use in non-commercial applications though. In this tutorial we are going to explore how to integrate it with a Django project to render dynamically generated charts. In relation to drawing the charts and rendering it to the client, all the hard work is done by Highcharts at the client side. The configuration and setup is pure JavaScript. The main challenge here is on how to translate the data from your backend to a format that Highcharts will understand. This data may come from a database or an external API, and probably is represented as Python objects (like in a QuerySet), or simply be represented as Python dictionaries or lists. Generally speaking, there are two ways to do it: Via the request/response cycle, using Python and the Django template engine to write the JavaScript code directly in the template; Via an async request using AJAX, returning the data in JSON format. The first option is like a brute force and in many cases the easiest way. The second … -
The Moment
When social media was small, it was a bubble: a quiet conversation among friends. It was nice, but not particularly challenging. Pleasant, but maybe not useful. Then there was a moment. A short one. Social media was perfect. The bubble popped, and suddenly there were voices from outside the bubble. But it was still small, still manageable, not yet the all-consuming force it is today. I felt comfortable sharing all sorts of things. -
Testing Django applications in 2018
I spend a lot of time writing Django applications. At each of my last three jobs I worked with Django, and I’m the primary maintainer of quite a few open-source Django applications. Which means I’ve written a lot of tests for code that uses Django. And although Django provides a lot of useful tools for testing, there are areas where it doesn’t prescribe or even suggest how you should do things, and over the years ... Read full entry -
Django Rest Framework User Authentication Tutorial
Build a Django API with login, logout, and signup token-based endpoints. -
Writing A New Blog Engine
Since around February of 2012, I've been publishing this blog as a static HTML site using Pelican. The experience was pretty good, but over time I ran into a few problems with the fact that I never upgraded the site to match current versions of Pelican. Which meant the following: My RSS feed didn't follow the modern W3C RSS/Atom specifications. So I haven't been published in Planet Python in years. As time went by, upgrading to modern Pelican became harder and harder. And trying to get it to work wasn't much fun either. So I started looking at other options. My requirements: All my old page links needed to work. I didn't want to have to cook up some kind of redirect system. I wanted to be able to make customizations without fighting through a complex extension system. Theming needed to be easy. Markdown needed to be supported. While I like RestructuredText, the honest truth is that I can pour out my thoughts faster with Markdown. With those requirements in mind, I got started reviewing other tools. I tried a bunch of options (Hugo, Lektor, Pelican again, etc) but none of them met my requirements to the degree I wanted. … -
Python Asyncio Web Scraping
A lot of Python programs are S... -
What to use at my new job: mac or linux?
First things first: "new job"? Yes, I'm switching jobs. I'll give more details once my new job actually has a website. They're quite a new company :-) Question: "new job" means "new laptop". And I'm wondering if you could give me some input on whether to ask for a mac or a linux laptop. What is currently the best choice? (Yes, windows is totally out). For the last 15 years I've only used macbooks, apart from the first year at my current job. After that first year I managed to switch back to apple. Before those 15 years I used linux desktops (slackware, suse, debian, mandrake) for 10 years. And before that windows 3.1. Some of my thoughts: The three year old macbook pro 15" I have now is such a wonderful machine. Well made. Great screen. If someone looks over your shoulder, they actually see what is on your screen. On many laptops, you have to sit right in front of it, because the screen starts to darken if you look at it from an angle. Not so on my macbook. Oh, and the sharpness of the characters.... I'm someone who really enjoys such beauty. The best trackpad there … -
Facebook Messenger Bot with Django
We still have to do a live tes... -
A Multiple Model Django Search Engine
The Django [ORM](https://en.wi... -
Making mistakes
A couple weeks ago when I was writing what became pwned-passwords-django, I tweeted about a weird issue I was seeing when running the tests for part of it. As it turned out, I’d overlooked something important, and the fix ended up being a one-line change. But that kicked off a little side discussion about the importance of being open about these kinds of “trivial” mistakes; it’s easy for newer or less-confident programmers to do something ... Read full entry -
Thoughts on Publishing a Technical Book (Part 2)
What I've learned writing and self-publishing a book on web development with Django. -
Tutorial: Django REST with React (Django 3 and a sprinkle of testing)
I gave a talk: "Decoupling Django with Django REST and React" at Pycon Italy X in Florence. Slides here! Django REST with React: what you will learn In the following tutorial you’ll learn: how to build a simple Django REST API how to structure a Django project with React Django REST with React: requirements To follow along with the tutorial you should have: a basic understanding of Python and Django. a basic understanding of JavaScript (ECMAScript 2015) and React. a newer version of Node.js installed on your system Ready? Let's get started! Django REST with React: setting up a Python virtual environment, and the project First things first make sure to have a Python virtual environment in place. Create a new folder and move into it: mkdir django-react && cd $_ Once done create and activate the new Python environment: python3 -m venv venv source venv/bin/activate NOTE: from now on make sure to be always in the django-react folder and to have the Python environment active. Now let's pull in the dependencies: pip install django djangorestframework When the installation ends you're ready to create a new Django project: django-admin startproject django_react . Now we can start building our first Django … -
HOWTO: Working with Python, Unicode, and Arabic
When working with non-European languages such as Arabic and Chinese, a practical understanding of Unicode is necessary. My research group uses Java for larger applications, and although Java represents all strings in Unicode, it is often cumbersome to write small Java applications for the various data manipulation tasks that appear while preparing corpora for translation. Therefore, fluency in one of the dynamically-typed scripting languages can be immensely useful in this particular domain. I prefer Python for its intuitive Unicode support and minimalist syntax. This article provides sample Python code for several common use cases that require particular consideration of string encodings. Perl offers analogous capabilities, but Ruby’s Unicode support is somewhat limited as of Ruby 1.9. (Note that this document is valid for Python 2.5.x only; Python3k introduces numerous incompatibilities.) Working with Strings Python supports two methods of constructing Unicode strings. The unicode() built-in function constructs a string with a default encoding of utf-8. The u” shorthand notation is equivalent: best = unicode('?????', encoding='utf-8') #Preferred method old = u'?????' #Deprecated in Python3k To convert between one encoding and another, use the string method encode(): ascii_string = 'My anglo-centric string...' utf8_string = ascii_string.encode('utf-8') #Concatenation works as expected utf8_string = utf8_string + … -
How Django URLs work with Regular Expressions
Let's better understand Django... -
Two new projects
Django and security are two of my favorite topics, and I think they go pretty well together. I’ve given a number of conference talks and tutorials on the theme of Django and security, and I’m one of the people on the receiving end of Django’s security-reporting email address. But although I spend a lot of time thinking about security, and trying to improve the state of the world through code, and occasionally ranting on various ... Read full entry -
Building Modern Applications with Django, Vue.js and Auth0: Part 2
This tutorial series are first created for Auth0 blog. Part 2 and 3 will be published in my blog with the permission from the Auth0. As of part 1 you can read it in the Auth0 blog once it's published. In this tutorial you will learn What is Webpack and why you should use it? The Webpack template used by the Vue CLI to generate Vue applications based on Webpack how to integrate Vue with Django so you can serve the front end application using Django instead of having complete separate front end and back end apps how to fix Hot Code Reloading when using Django to serve the Vue application how to update the Callback URL for Auth0 authentication Introduction to Webpack In this section we you briefly get introduced to Webpack (and why you should use Webpack?) Essentially webpack is a static module bundler for modern JavaScript applications which becomes a fundamental tool with the rise of modern JavaScript front end frameworks such as Angular, React and Vue. It also can be easily configured to bundle other assets such as HTML, CSS and images via loaders. It will help you reduce the number of requests and round trips … -
Building a Modern Web Application with Django REST Framework and Vue: Building Views and REST API
Throughout this part of these tutorial series you will continue developing a CRUD (Create, Read, Update and Delete) application with a restful API back-end and a Vue front-end using Django, Django REST framework and Vue (with Axios as an HTTP client). In this part you'll specifically build the REST API and the front-end views to consume and display data from the API endpoints. You will also see how to integrate your Vue application with your Django back-end in production. As always you can find the source code of the demo project in this Github repository. You can check the second article from this link Summary This article is composed of the following sections: Building the REST API: You will create a simple REST API around one model (Product) with DRF and learn how to add pagination to your APIs. Creating the Service to Consume the API: You will create the class that interfaces with your API using Axios. Creating the Front End Views: You will create different views and routes for the Vue application and see how you can protect some routes from non authenticated users. Getting Ready for Production: Finally you'll prepare your app for production by tweaking some … -
Building Modern Applications with Django, Vue.js and Auth0: Part 1
I originally created this tutorial series for Auth0 blog and are published here with the permission from the technical author at Auth0 Throughout this series, you'll be using Django, Django REST framework, and Vue.js to develop an application with a REST API back-end and a Vue.js front-end. The API will be consumed by the Vue.js front-end with the help of the Axios client library and JWT authentication will be handled by Auth0. You are going to start by installing all the project's requirements, then you will bootstrap the Django and the Vue.js sub-projects. You can find the final source code of the demo project that you will create in this GitHub repository. Summary This article is composed of the following sections: Introduction to Python and Django Introduction to Vue.js and Vue.js Features Bootstrapping the Back-End Project Bootstrapping the Front-End Project Introduction to JSON Web Tokens Integrating Django with Auth0 Integrating Auth0 with Vue.js Conclusion and Next Steps Introduction to Python and Django Python is a general-purpose programming language and it's among the most popular programming languages in the world. It's readable, efficient, and easy to learn. Python is also a portable language available for major operating systems such as Linux, … -
Building a Modern Web Application with Django REST Framework and Vue: Building Views and REST API
Throughout this part of these tutorial series you will continue developing a CRUD (Create, Read, Update and Delete) application with a restful API back-end and a Vue front-end using Django, Django REST framework and Vue (with Axios as an HTTP client). In this part you'll specifically build the REST API and the front-end views to consume and display data from the API endpoints. You will also see how to integrate your Vue application with your Django back-end in production. As always you can find the source code of the demo project in this Github repository. You can check the second article from this link Summary This article is composed of the following sections: Building the REST API: You will create a simple REST API around one model (Product) with DRF and learn how to add pagination to your APIs. Creating the Service to Consume the API: You will create the class that interfaces with your API using Axios. Creating the Front End Views: You will create different views and routes for the Vue application and see how you can protect some routes from non authenticated users. Getting Ready for Production: Finally you'll prepare your app for production by tweaking some … -
Django REST Framework Read & Write Serializers
Django REST Framework (DRF) is a terrific tool for creating very flexible REST APIs. It has a lot of built-in features like pagination, search, filters, throttling, and many other things developers usually don't like to worry about. And it also lets you easily customize everything so you can make your API work the way you want. There are many gene -
csso and django-pipeline
This is a quick-and-dirty how-to on how to use csso to handle the minification/compression of CSS in django-pipeline. First create a file called compressors.py somewhere in your project. Make it something like this: import subprocess from pipeline.compressors import CompressorBase from django.conf import settings class CSSOCompressor(CompressorBase): def compress_css(self, css): proc = subprocess.Popen( [ settings.PIPELINE['CSSO_BINARY'], '--restructure-off' ], stdin=subprocess.PIPE, stdout=subprocess.PIPE, ) css_out = proc.communicate( input=css.encode('utf-8') )[0].decode('utf-8') # was_size = len(css) # new_size = len(css_out) # print('FROM {} to {} Saved {} ({!r})'.format( # was_size, # new_size, # was_size - new_size, # css_out[:50] # )) return css_out In your settings.py where you configure django-pipeline make it something like this: PIPELINE = { 'STYLESHEETS': PIPELINE_CSS, 'JAVASCRIPT': PIPELINE_JS, # These two important lines. 'CSSO_BINARY': path('node_modules/.bin/csso'), # Adjust the dotted path name to where you put your compressors.py 'CSS_COMPRESSOR': 'peterbecom.compressors.CSSOCompressor', 'JS_COMPRESSOR': ... Next, install csso-cli in your project root (where you have the package.json). It's a bit confusing. The main package is called csso but to have a command line app you need to install csso-cli and when that's been installed you'll have a command line app called csso. $ yarn add csso-cli or $ npm i --save csso-cli Check that it installed: $ ./node_modules/.bin/csso --version 3.5.0 … -
How to add Wagtail page programmatically via Python script
Given: Two Wagtail CMS page classes: class Section(Page): subtitle = models.Charfield(max_length=128) class News(Page): content = models.Textfield() Task: Using a python script, add a News page item under the Section page titled "Latest news." Solution: 1) Get parent page instance: parent_page = Page.objects.get(title='Latest news' ... Read now -
Basics of Django Rest Framework
What Is Django Rest Framework? Django Rest Framework (DRF) is a library which works with standard Django models to build a flexible and powerful API for your project. Basic Architecture A DRF API is composed of 3 layers: the serializer, the viewset, and the router. Serializer: converts the information stored in the database and defined by the Django models into a format which is more easily transmitted via an API Viewset: defines the functions (read, create, update, delete) which will be available via the API Router: defines the URLs which will provide access to each viewset Serializers Django models intuitively represent data stored in your database, but an API will need to transmit information in a less complex structure. While your data will be represented as instances of your Model classes in your Python code, it needs to be translated into a format like JSON in order to be communicated over an API. The DRF serializer handles this translation. When a user submits information (such as creating a new instance) through the API, the serializer takes the data, validates it, and converts it into something Django can slot into a Model instance. Similarly, when a user accesses information via the … -
Container Runtimes Part 2: Anatomy of a Low-Level Container Runtime
This is the second in a four-part series on container runtimes. In part 1, I gave an overview of container runtimes and discussed the differences between low-level and high-level runtimes. In this post I will go into detail on low- level container runtimes. Low-level runtimes have a limited feature set and typically perform the low- level tasks for running a container. Most developers shouldn't use them for their day-to-day work. Low-level runtimes are usually implemented as simple tools or libraries that developers of higher level runtimes and tools can use for the low-level features. W[...]