Django admin — Display time in the current timezone

I had a Django project where a cronjob will run at certain intervals and add an entry in the database if the task is executed successfully. My project used UTC as the default timezone. When I look at the execution time of the tasks in the Django-admin site all the execution times were in UTC. Although it […]

Read More
  • Posted by allwinraju
  • December 20, 2020
  • 0 Comments

Cookies in Django – Setting, retrieving and deleting cookies

HTTP is a stateless protocol so when a request is sent to the server, it does not know whether you are requesting the page for the first time or you are the same user who has visited this page many times before. This HTTP statelessness was a problem for ecommerce website developers because persistence among […]

Read More
  • Posted by allwinraju
  • December 8, 2020
  • 0 Comments

XML response in Django using Django-rest-framework

In this article, we shall see how to return the response from our Django project in XML format instead of the traditional JSON response. We have to install a third-party package first in order to render XML response. REST Framework XML provides a simple informal XML format. It was previously included directly in the REST […]

Read More

Basic authentication in Django

In this article we shall see how to work with basic authentication in django. But before that first let us see what Basic authentication is. What is “Basic authentication“? Basic authentication adds a header like below to the HTTP requests. Basic authentication creates the token by taking a username and a password joins them with […]

Read More

Django update queryset in a single line

I recently came across a problem, where I had to set or alter a boolean field from True to False for all the objects of a queryset. I did not want to use a for loop to iterate over them, change the value from False to True, and save it. I looked over a solution […]

Read More

django get first and last element from a queryset

In django a queryset is similar to a list but does not support negative indexing like a normal list. This makes it difficult to get the last element by traditional method. Let us say we have a model like this. This is a simple post model which have two fields “title” and “date”. If we […]

Read More

Create custom manage.py commands in django

Often times during Django project development, there is a need to write one-off scripts that do something. As a self-taught developer, there are many ways to accomplish this, and I for one, did this completely wrong for years. My original strategy as a beginner-interediate level developer was to create view functions that contained my logic alongside URLs that […]

Read More