The goal of this article is to discuss the caveats of the default Django user model implementation and also to give you some advice on how to address them. It is important to know the limitations of the current implementation so to avoid the most common pitfalls. Something to keep in mind is that the Django user model is heavily based on its initial implementation that is at least 16 years old. Because user and authentication is a core part of the majority of the web applications using Django...| Simple is Better Than Complex
In this tutorial I’m going to show you how I usually start and organize a new Django project nowadays. I’ve tried many different configurations and ways to organize the project, but for the past 4 years or so this has been consistently my go-to setup. Please note that this is not intended to be a “best practice” guide or to fit every use case. It’s just the way I like to use Django and that’s also the way that I found that allow your project to grow in healthy way. Index Premises ...| Simple is Better Than Complex
Chart.js is a cool open source JavaScript library that helps you render HTML5 charts. It is responsive and counts with 8 different chart types. In this tutorial we are going to explore a little bit of how to make Django talk with Chart.js and render some simple charts based on data extracted from our models. Installation For this tutorial all you are going to do is add the Chart.js lib to your HTML page: <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"></script> You...| Simple is Better Than Complex
In this tutorial you are going to learn how to pass extra data to your serializer, before saving it to the database. Introduction Example Using APIView Example Using ViewSet Introduction When using regular Django forms, there is this common pattern where we save the form with commit=False and then pass some extra data to the instance before saving it to the database, like this: form=InvoiceForm(request.POST)ifform.is_valid():invoice=form.save(commit=False)invoice.user=request.userinvoice.save...| Simple is Better Than Complex
In this tutorial we are going to explore three date/datetime pickers options that you can easily use in a Django project. We are going to explore how to do it manually first, then how to set up a custom widget and finally how to use a third-party Django app with support to datetime pickers. Introduction Tempus Dominus Bootstrap 4Direct Usage Custom Widget XDSoft DateTimePickerDirect Usage Custom Widget Fengyuan Chen’s DatepickerDirect Usage Custom Widget Conclusions --- Introduction The imp...| Simple is Better Than Complex
The Django forms API have two field types to work with multiple options: ChoiceField and ModelChoiceField. Both use select input as the default widget and they work in a similar way, except that ModelChoiceField is designed to handle QuerySets and work with foreign key relationships. A basic implementation using a ChoiceField would be: classExpenseForm(forms.Form):CHOICES=((11,'Credit Card'),(12,'Student Loans'),(13,'Taxes'),(21,'Books'),(22,'Games'),(31,'Groceries'),(32,'Restaurants'),)amoun...| Simple is Better Than Complex
JWT stand for JSON Web Token and it is an authentication strategy used by client/server applications where the client is a Web application using JavaScript and some frontend framework like Angular, React or VueJS. In this tutorial we are going to explore the specifics of JWT authentication. If you want to learn more about Token-based authentication using Django REST Framework (DRF), or if you want to know how to start a new DRF project you can read this tutorial: How to Implement Token Authen...| Simple is Better Than Complex
[Django 2.1.3 / Python 3.6.5 / Bootstrap 4.1.3] In this tutorial we are going to explore some of the Django Crispy Forms features to handle advanced/custom forms rendering. This blog post started as a discussion in our community forum, so I decided to compile the insights and solutions in a blog post to benefit a wider audience. Table of Contents Introduction Installation Basic Form Rendering Basic Crispy Form Rendering Custom Fields Placement with Crispy Forms Crispy Forms Layout Helpers Cus...| Simple is Better Than Complex
In this tutorial you are going to learn how to implement Token-based authentication using Django REST Framework (DRF). The token authentication works by exchanging username and password for a token that will be used in all subsequent requests so to identify the user on the server side. The specifics of how the authentication is handled on the client side vary a lot depending on the technology/language/framework you are working with. The client could be a mobile application using iOS or Androi...| Simple is Better Than Complex
In this tutorial series, we are going to explore Django's authentication system by implementing sign up, login, logout, password change, password reset and p...| Simple is Better Than Complex