Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
How to Setup Amazon S3 in a Django Project
In this tutorial you will learn how to use the Amazon S3 service to handle static assets and the user uploaded files, that is, the media assets. First, I will cover the basic concepts, installation and configuration. Then you will find three sections covering: Working with static assets only Working with static and media assets Mixing public assets and private assets Dependencies You will need to install two Python libraries: boto3 django-storages The boto3 library is a public API client to access the Amazon Web Services (AWS) resources, such as the Amazon S3. It’s an official distribution maintained by Amazon. The django-storages is an open-source library to manage storage backends like Dropbox, OneDrive and Amazon S3. It’s very convenient, as it plugs in the built-in Django storage backend API. In other words, it will make you life easier, as it won’t drastically change how you interact with the static/media assets. We will only need to add a few configuration parameters and it will do all the hard work for us. Amazon S3 Setup Before we get to the Django part, let’s set up the S3 part. We will need to create a user that have access to manage our S3 … -
Episode #1 - Brian Michael Riley
Do you like riding a bike? If ... -
Django, Virtualenv, & Python .gitignore File
We use `.gitignore` files ofte... -
Django, GraphQL & React - part two
In this post, I will guide you through setting up GraphQL with Django. Let's get started! I will use a library called graphene-django. It will help a lot and allow me to get the job done instead of writing boilerplate code. I decided I will have 3 django applications: actors … -
Django REST Framework Authentication by Example with JSON Web Tokens (JWT)
Introduction Django Rest Framework provides multiple mechanisms for authenticating users, in case you are new to this concept then simply put: authentication is the process of identifying a logged in user, while authorization is identifying if the user has authorized access to some server resource. In this tutorial, we are going to see what's the DRF available mechanisms to authenticate users, what is the difference between DRF built in token based auth system and JWT auth and then how to add JSON Web Tokens authentication to Django Rest Framework. How to Authenticate a User? The general process of authenticating a user is done by simply checking if any user information or credentials are attached to an incoming (from the client) request. DRF has already three mechanisms to authenticate users, lets look at each one of them: Basic Authentication: It's very easy to setup but only recommended for testing purposes not for production. It's implemented in rest_framework.authentication.BasicAuthentication class. And works by base64 encoding the user login information i.e the username and the password and attach them to an HTTP Authorization Header (can then be retrieved from request.META.HTTP _ AUTHORIZATION). Session Based Authentication: The traditional authentication mechanism and default one used by … -
Install Django on Linux Ubuntu
# Install Django & Virtualenv ... -
Find static files defined in django-pipeline but not found
If you're reading this you're probably familiar with how, in django-pipeline, you define bundles of static files to be combined and served. If you're not familiar with django-pipeline it's unlike this'll be of much help. The Challenge (aka. the pitfall) So you specify bundles by creating things in your settings.py something like this: PIPELINE = { 'STYLESHEETS': { 'colors': { 'source_filenames': ( 'css/core.css', 'css/colors/*.css', 'css/layers.css' ), 'output_filename': 'css/colors.css', 'extra_context': { 'media': 'screen,projection', }, }, }, 'JAVASCRIPT': { 'stats': { 'source_filenames': ( 'js/jquery.js', 'js/d3.js', 'js/collections/*.js', 'js/aplication.js', ), 'output_filename': 'js/stats.js', } } } You do a bit more configuration and now, when you run ./manage.py collectstatic --noinput Django and django-pipeline will gather up all static files from all Django apps installed, then start post processing then and doing things like concatenating them into one file and doing stuff like minification etc. The problem is, if you look at the example snippet above, there's a typo. Instead of js/application.js it's accidentally js/aplication.js. Oh noes!! What's sad is it that nobody will notice (running ./manage.py collectstatic will exit with a 0). At least not unless you do some careful manual reviewing. Perhaps you will notice later, when you've pushed the site to prod, that … -
Two Scoops of Django Birthday Giveaway
Today is a special day. You see, the latest fantasy book I co-authored, Coldest Spring (3rd in the Ambria series), is out AND it's my birthday. In honor of of these occasions, the first book of the series, Darkest Autumn, for 0.99 cents on Amazon. Plus, I'm doing a Python-related giveaway. The Giveaway: There’s a python programming easter egg in the book. One of the characters mentions the elegance of Python. The first person who tells me in the comments below the name of the father and grandfather of that character gets an autographed Two Scoops of Django 1.11 book shipping anywhere in the world. Finally, if you want to give me a truly special present for my birthday, please review any or all of my books on Amazon. Positive or negative, every review makes a difference. The positive stuff feeds my already inflated ego, and the negative stuff tells me what I need to do in order to improve. Two Scoops of Django 1.11 Ambria 1: Darkest Autumn (Just $0.99 for the rest of July 2017!) Ambria 2: Brightest Winter Ambria 3: Coldest Spring -
Two Scoops of Django Birthday Giveaway
Today is a special day. You see, the latest fantasy book I co-authored, Coldest Spring (3rd in the Ambria series), is out AND it's my birthday. In honor of of these occasions, the first book of the series, Darkest Autumn, for 0.99 cents on Amazon. Plus, I'm doing a Python-related giveaway. The Giveaway: There's a python programming easter egg in the book. One of the characters mentions the elegance of Python. The first person who tells me in the comments below the name of the father and grandfather of that character gets an autographed Two Scoops of Django 1.11 book shipping anywhere in the world. Finally, if you want to give me a truly special present for my birthday, please review any or all of my books on Amazon. Positive or negative, every review makes a difference. The positive stuff feeds my already inflated ego, and the negative stuff tells me what I need to do in order to improve. Two Scoops of Django 1.11 Ambria 1: Darkest Autumn (Just \$0.99 for the rest of July 2017!) Ambria 2: Brightest Winter Ambria 3: Coldest Spring Updates July 24th 3pm: A commenter by the name of @lingot answered first and they'll … -
Is Django the Right Fit for your Project?
You need a website. You may have done some searches, and come back overwhelmed and empty-handed, having found hosting providers offering services that may have sounded familiar (“WordPress”) and ones that may have sounded like a foreign language (“cPanel”). You may have considered hiring someone to build your website, and gotten conflicting answers about what you need and what it would cost. You may have also heard about Django, but you’re not sure how it it fits into the picture and whether or not it’s the right fit for your project. This is common, because there are many different types of websites out there. To help answer the question of whether Django is the right fit for your project, let’s take a look at the landscape. -
Organizing Django Girls Recife
In Brazil, women are the majority in schools and universities and represent 60% of the people who have a university degree. Despite this, in STEM, they represent only 20% of the quantitative. This scenario is present not only in Brazil but all over the world. In technological areas, it’s no different. IT is still a mostly male world. It was with th -
[pt-BR] Organizando o Django Girls Recife
No Brasil, as mulheres são maioria nas escolas e universidades e representam 60% das pessoas que concluíram cursos superiores. Apesar disso, em cursos de exatas, representam apenas 20% do quantitativo. Esse cenário se repete não só no Brasil, mas em todo o mundo. Nas áreas tecnológicas não é diferente. TI é, ainda, um mundo majoritariamente masculi -
PyDelhi Conf 2017: A beautiful conference happened in New Delhi, India
TL;DR PyDelhi conf 2017 was a two-day conference which featured workshops, dev sprints, both full-length and lightning talks. There were workshop sessions without any extra charges. Delhiites should not miss the chance to attend this conference in future. I conducted a workshop titled “Tango with Django” helping beginners to understand the Django web framework. Detailed Review About the PyDelhi community PyDelhi conf 2017 volunteers The PyDelhi community was known as NCR Python Users Group before few years. This community is performing a role of an umbrella organization for other FLOSS communities across New Delhi, India. They are actively arranging monthly meetups on interesting topics. Last PyCon India which is a national level conference of Python programming language was impressively organized by this community. This year too they took the responsibility of managing it. I am very thankful to this community for their immense contribution to this society. If you are around New Delhi, India then you should not miss the chance to attend their meetups. This community has great people who are always happy to mentor. PyDelhi conf 2017 Conference T-shirt PyDelhi conf is a regional level conference of Python programming language organized by PyDelhi community. It is their second … -
Implementing JWT in Django
In the beginning there were Sessions In a typical HTTP Request/Response cycle with Django, the sessions framework is used to authenticate users. How it works in the normal case is that each visitor to the site is assigned a session id which is saved in the database. A cookie is then generated which contains the unique session id and is returned to the client to be attached to subsequent requests. Django’s Session Middlware will intercept the cookie that is passed with future requests and get the corresponding session from the database. In this way, no information from the session is ever passed to the client. The session can hold any arbitrary information like whether the user is authenticated or anonymous, their user id in the database, or anything else a developer might want to store about visitors. The major concept with sessions is that it is a stateful form of authentication. Stateful in this context means that the server holds the state of each user at all times. If there was ever a security concern about a user the server can arbitrarily destroy their session or limit a session and its access for a period of time. The downside that … -
Django Anti-Patterns: Signals
Django's Signal Dispatcher is a really powerful feature that you should never use. Ok, it has valid use cases, but they may be rarer than you think. First, to dispell a misconception about signals, they are not executed asynchronously. There is no background thread or worker to execute them. Like most of Django, they are fully "synchronous". I suspect this misconception stems from the event-driven coding pattern they use which is often seen in asynchronous languages/libraries. The event-driven pattern of signals looks neat at first, but often I see them mentioned as a source of frustration. It's not the author complaining, but the poor soul who inherits maintenance of the code and only learns of the existitance of signals when trying to track down unexpected behavior. Consider the following example using signals: # File: models.py from django.db import models class Pizza(models.Model): has_pepperoni = models.BooleanField(default=False) class ToppingSales(models.Model): name = models.CharField(max_length=100, unique=True) units_sold = models.PositiveIntegerField(default=0) # File: signals.py from django.db.models.signals import post_save from django.db.models import F from django.dispatch import receiver from .models import Pizza def pizza_saved_handler(sender, instance, created, **kwargs): if created and instance.has_pepperoni: ToppingSales.objects.filter(name='pepperoni').update( units_sold=F('units_sold') + 1) # File: app.py from django.apps import AppConfig from django.db.models.signals import post_save class PizzeriaConfig(AppConfig): def ready(self): … -
Caktus at DjangoCon2017
In less than a month we’ll be heading out to Spokane, WA for DjangoCon 2017. We’re proud to be attending as sponsors for the eighth year, and look forward to greeting everyone at our booth. On August 16th, we’ll be raffling off a GoPro Session action camera, so be sure to stop by and enter. We’ll also have our comfy new t-shirts and some limited-edition Caktus 10th Anniversary water bottles to give away. They went fast at PyCon, so don’t wait to get yours. -
Building Web Apps with Django and Angular 2+ CLI
Angular CLI is a command line utility which enables you to quickly generate and build Angular 2+ apps .It takes care of much of the configuration and let you focus on implementing your next idea so it's a great tool for bootstraping modern JavaScript projects based on Angular 2+ . In this tutorial we are going to see how to serve and integrate an Angular 2+ web application (as a frontend ) with a Django backend . Communication between Django and Angular 2+ happens through a Restful API ,so for testing if our integration works, as expected ,you need to have a small testing API built in the Django backend . You can use any Rest API generator for Django such as Django Rest Framework (DRF) or Tastypie to build some API endpoints . I have previously created an API for a simple product manager app with Django and DRF so I'm going to use it in this tutorial to test the integration with the Angular 2+ frontend app . Requirements Before we can start building our demo app ,there are some requirements that we need to have installed on our system : Python , Virtualenv and PIP . Node.js … -
Building Web Apps with Django ,Webpack and React
Throughout this tutorial we are going to learn how to use React JavaScript library and Webpack with Django to create modern web applications . Webpack is a module bundler and a build tool that bundles JavaScript and other assets for better consuming by web browsers . The aim of this tutorial is to show you the steps for using React with Webpack as the front end of your Django web applications . So lets get started ! Create a virtual environment Lets start by creating a virtual environment using virtualenv so open your terminal then run : virtualenv myenv Next activate the environment with : source myenv/bin/activate Next install Django using pip : pip install django Then create a django project : django-admin.py startproject django-react-demo To be able to install npm modules we need to create an npm module .This can be done by adding a package.json with some information to a folder which marks the folder as an npm module . Add package.json Generate a package.json inside your project root folder using : npm init npm will ask you for some information ,enter them and hit Enter . Now lets install the npm dependencies we need in our project … -
Building a Modern App with Django and React
React is a JavaScript library for building powerfull user interfaces. It's developed by Facebook and used by developers worldwide. Create React App is an npm tool to generate React apps without any build configurations for tools such as Webpack or Babel .That doesn't mean these tools are not used but they are just hidden so you can focus on building your React app instead of setting up build environments . By issuing a few commands you can generate a React app and start building your next idea in time record but if you need to integrate your app with a server framework such as Django in our case we still need to do little configuration so you can deploy your React app as a static front end for your Django project . In this How To tutorial we are going to see how to use Create React App with Django to create our Django app front end using React in both development and production environments . Lets start by generating a Django project from scratch : $ virtualenv env $ source env/bin/activate $ pip install django $ django-admin.py startproject django-react-demo $ cd django-react-demo Create some API endpoints with Django Rest … -
Building Web Apps with Django ,Webpack and React
Throughout this tutorial we are going to learn how to use React JavaScript library and Webpack with Django to create modern web applications . Webpack is a module bundler and a build tool that bundles JavaScript and other assets for better consuming by web browsers . The aim of this tutorial is to show you the steps for using React with Webpack as the front end of your Django web applications . So lets get started ! Create a virtual environment Lets start by creating a virtual environment using virtualenv so open your terminal then run : virtualenv myenv Next activate the environment with : source myenv/bin/activate Next install Django using pip : pip install django Then create a django project : django-admin.py startproject django-react-demo To be able to install npm modules we need to create an npm module .This can be done by adding a package.json with some information to a folder which marks the folder as an npm module . Add package.json Generate a package.json inside your project root folder using : npm init npm will ask you for some information ,enter them and hit Enter . Now lets install the npm dependencies we need in our project … -
Building Apps with Create React App and Django
Create React App is an npm tool to generate React apps without any build configurations for tools such as Webpack or Babel .That doesn't mean these tools are not used but they are just hidden so you can focus on building your React app instead of setting up build environments . By issuing a few commands you can generate a React app and start building your next idea in time record but if you need to integrate your app with a server framework such as Django in our case we still need to do little configuration so you can deploy your React app as a static front end for your Django project . In this How To tutorial we are going to see how to use Create React App with Django to create our Django app front end using React in both development and production environments . Lets start by generating a Django project from scratch : $ virtualenv env $ source env/bin/activate $ pip install django $ django-admin.py startproject django-react-demo $ cd django-react-demo Create some API endpoints with Django Rest Framework Since the communication between React and Django happens over an API we need to create some Django API … -
Building Go Applications with Google Container Builder
Gopher image Creative Commons Attribution 3.0 Unported (ja) by tenntenn Recently I wrote on Twitter about how doing CI right requires you to properly separate your build and run steps for your container images. > i.e. you have one Docker image to build your Go static binary, and one that's 3 lines long to copy it into a scratch image ;) > > -- Ian Lewis (@IanMLewis) May 20, 2017 The reason for this issue is that you want to keep your final image as small as possible for a number of reasons. The obvious reason is for performance but there are several other reasons. Keeping it small ke[...] -
Building Go Applications with Google Container Builder
Gopher image Creative Commons Attribution 3.0 Unported (ja) by tenntenn Recently I wrote on Twitter about how doing CI right requires you to properly separate your build and run steps for your container images. > i.e. you have one Docker image to build your Go static binary, and one > that's 3 lines long to copy it into a scratch image ;) > > -- Ian Lewis (@IanMLewis) May 20, 2017 The reason for this issue is that you want to keep your final image as small as possible for a number of reasons. The obvious reason is for performance but there are several other reasons. Keeping it small ke[...] -
Getting started with Django Rest Framework by Building a Simple Product Inventory Manager
Django offers developers many packages/frameworks to build web Rest APIs ,among them Django Rest Framework or DRF which is by far the most popular and powerful Rest API Framework . In this tutorial we will see how to use DRF to create a Rest API for a simple products inventory manager with 4 models . Getting started Lets start by following these steps : Create a virtual environement . Install both Django and Django Rest Framework . Create A Django project . Create a Django app . Add database models in inventory/models.py # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models class Product(models.Model): sku = models.CharField(max_length=13,help_text="Enter Product Stock Keeping Unit") barcode = models.CharField(max_length=13,help_text="Enter Product Barcode (ISBN, UPC ...)") title = models.CharField(max_length=200, help_text="Enter Product Title") description = models.TextField(help_text="Enter Product Description") unitCost = models.FloatField(help_text="Enter Product Unit Cost") unit = models.CharField(max_length=10,help_text="Enter Product Unit ") quantity = models.FloatField(help_text="Enter Product Quantity") minQuantity = models.FloatField(help_text="Enter Product Min Quantity") family = models.ForeignKey('Family') location = models.ForeignKey('Location') def get_absolute_url(self): """ Returns the url to access a particular instance of Product. """ return reverse('product-detail-view', args=[str(self.id)]) def __str__(self): return self.title class Family(models.Model): reference = models.CharField(max_length=13, help_text="Enter Family Reference") title = models.CharField(max_length=200, help_text="Enter Family Title") description = models.TextField(help_text="Enter … -
How to Customize Django Admin Application
Django Admin interface or app is a powerful feature of Django framework as it allows you to automatically scaffold a full featured CRUD application for your database models saving you from reinventing the wheel when building admin interfaces or back offices for your projects .It can also be used for building quick prototypes . Most developers are not aware of the hidden power of Django admin so in this tutorial we are going to show you how we can extend it to customize its look and also its behavior with custom actions . The Admin site is enabled by default in each generated Django project . To create an admin site or back office you need to follow these predefined steps : First create your database models in models.py Next register your models with Django Admin in admin.py module . Customize the admin area with optional look or custom actions and views . Lets use the models from a simple product inventory manager where we have 4 models : Product ,Family , Location and Transaction . After creating a skeleton project with django-admin.py utility .You'll have Django admin already included and configured for you all you have to do is …