Django App Starter Template

Archie To

Django App Starter Template: https://gitlab.com/uvic-arcsoft/strap/app-starter-django/-/tree/archie

Introduction - Existing Problem

Django is a very popular web framework known by many Python developers. RCS ARC Software Team decided to use this framework as the main technology to develop multiple web applications, which will eventually serve the need of researchers, falcuty members and employees in the University of Victoria. All of these applications have some identical functionalities such as authenticating users by HTTP request headers, displaying separated pages for normal users and admin users, and providing an about page for web developers. These similar functionalities force engineers to rewrite the same code everytime they start a new project. This is obviously a time-consuming and boring process.

Solution - Description and Features

As a solution, I, Archie To, was assigned to write a Django template, called Django App Starter Template. This template aims to contain mandatory functionalities that every application created by the ARC Software Team must have. Developers when starting a new project can add code to this template. The functionalities implemented in the template are the followings:

  1. A basic Django project setup: Trim off unnecessary code, write some configurations, include necessary Python packages, Boostrap and jQuery, and provide a detailed documentation

  2. Basic routings and pages: a Login page at /login/, a Home page at /, an Admin page at /admin/ and an About modal

  3. A basic navigation bar: Allow users to navigate between pages mentioned above

  4. A setup for linting tests, unit and coverage tests: These tests can be run both manually locally or automatically on Gitlab CI

  5. Basic scripts for easier development: Include a script that updates the app version and a script that updates CHANGELOG.md.

These functionalities will be further developed and improved over time by me or other developers based on how we see fit.

Results - Usage and Outcome

Usage

This template has been used by me in two projects of the ARC Software team. These are RCDB and STRAPPER app manager. As a result you can see similarities in the styling and codebase of the two projects. I used it the first time on RCDB, realized there were some improvements that I could make, added those improvements to the template, then the process happened again with the second time I used it for STRAPPER.

Outcome

This saved me about one to two days setting up for each project. In addition, the codebase, tests and test reports are quite consistent between the two projects. This allows me to monitor and manage the code easily everytime I switch projects.

I hope in the future, developers in the ARC Software team, or even outside of the team, would continue using and making changes neccessary to the template.

Things I learned while writing the template

Differences between Flask and Django

The template was initially in Flask and my task was to convert the Flask sleketon code into Django. As a result, I had an exposure to Flask, while learning how to write Django at the same time. Building similar functionalities to the Flask template in Django allowed me to see the pros and cons between the two frameworks.

How to write good Django code

As I continuously built and improved the Django App Starter Template, I initially learnt to use the framework. Later on, I realized many parts of the my code didn’t follow good practices in Django. Therefore, I learnt to follow and implement more advanced Django concepts such as middlewares, class-based views and mixins. This allowed me to shorten my code by a huge amount and make multiple parts of the code more reusable.

How to test my code

This was the first time I had an exposure to code testing. I learnt what lint, unit and coverage testing was. I learnt what to cover in Django unit tests. I also learnt the syntax of writing tests itself.

How to work with CI

I’d never worked with CI/CD before. Working on this template required me to set up a Gitlab CI that runs the tests automatically every time the code is pushed to a Gitlab repository. Understanding the concept of CI/CD guided me into a different way of thinking about code; it is to always maximize automation when developing projects.

Note: I’m confident that I learnt more than the above. However, those were the main points.

Things I could have done better

I’m quite happy with my process working on the template. I did my best, I learnt many new things and I produced quite a decent product. However, knowing what I know now, it would have taken me less time to understand the purpose of the template as it did take me a while to understand what the template did. I would have developed the template in a shorter period of time. All that aside, I’m satisfied with my work on this template and I hope it will bring great benefits to the users.