Blog


Setting active navbar link in Django template

Here is probably the best way to set the active navbar link in Django template. Note, this needs no jQuery/ javascript. Step 1 Create named urls: from django.conf.urls import url, include from django.contrib import admin from django.conf import settings from django.conf.urls.static import static from .views import ( HomeView, AboutView, ContactView, LoginView, RegistrationView ) urlpatterns = […]




Adding login and registration in Django

Adding login and registration is very straight forward in Django. Note that Django provides a built in User model. User model exists ONLY for authentication. Use the User model to only store absolutely necessary info for authentication. Like Username and password (or if using custom user model, email and password.. I usually make the email […]




Adding reverse url lookup in Django

Reverse url lookup is very cool feature in Django that allows us to not hard-code urls in templates or controller logic. This helps us change the URLs later in urls.py and not have to make the same changes everywhere in templates and logic. Keep it DRY. To implement reverse url lookup, you need to do […]




Django Custom Queryset vs Custom Manager for Database queries

Note: this applies to Django >= 1.7 From the docs: A Manager is the interface through which database query operations are provided to Django models. At least one Manager exists for every model in a Django application. There are two reasons you might want to customize a Manager: to add extra Manager methods, and/or to […]




Adding Custom User model in Django – part 1

One of the first things I do after creating a new Django or Django Rest Framework project is to create a custom User model. Part 1 deals with case when you add custom User model right at the start of a project. In part 2, we deal with scenario when custom User model is added […]




Add eslint config file (eslintrc) to Vue project

If you created Vue project via vue create my_proj and had eslint enabled in the options, You should get a .eslintrc.js in the root folder. Sometimes, I have seen it isn’t created. Worry not, here is how you can generate it manually. Make sure you have eslint module in node_modules folder. Then in console, do […]




CSS common tricks – Avoid text wrapping at whitespace

  • December 11, 2019
  • CSS

Here is how to avoid wrapping of text in elements like btn, div etc (block, or inline-block elements). add this to the btn styling: white-space: nowrap; You will find this code often. We strip off any padding around ul because it is automatically added by browsers ul{ padding: 0; } If you want the list […]




Vertically center items in Vuetify v-app-bar

I was writing a navigation bar and wanted to center some buttons in the navbar. Here is how I did it. Note that there are many items in nav-bar which is not very good in terms of material design principles (for smaller screens). If there are that many items, it is advisable to put a […]




Add Axios to your Vue app

Install axios npm install –save axios Then goto src/ folder and add a file called RestAPIService.js. In this file we will reside all our AXIOS interfacing code and Rest API calls. The RestAPIService.js looks like this: import axios from ‘axios’; const API_URL = ‘http://localhost:8000/api’; export class RestAPIService{ constructor(){ } async getCodes() { const url = […]




Writing Custom Django Management Commands

Any command given with manage.py is called management command. Django comes with many built-in management commands like runserver, startapp etc. To see a full list of built-in management commands, type: python manage.py help The benefit of management command script is that this script executes within Django environment. You can run all of Django ORM queries […]