Introducing Edge - a Modern Django Project Template

A newer version has been announced

Have you ever begun creating a web app only to abandon it while setting it up? I have done it more times than I would have liked.

Many programming environments involve so much ritual to setup that we tend to forget what we set out to create. Recently, I had to setup an Android development environment from scratch. Despite downloading the latest version of the IDE, I waited until several additional updates downloaded to patch it to the latest version. The trend of packages getting more granular and updates being made several times a day is here to stay.

It is like if you have an idea for a painting then you have to go shopping for all the art-supplies first. But the moment you step out, you have lost your muse. Scientists call this encoding specificity or as a famous paper calls it “Walking through doorways causes forgetting.”

Django Projects

Of course, in Django I use startproject which builds an excellent but minimal project structure. But once I start coding I inevitably tend to install packages like the django braces. Most of my project use Bootstrap, so I end up downloading the bootstrap assets as well. Any non-trivial web app needs some login functionality, so I end up adding that too.

In short, by the time I have setup everything to actually start building the app, I have crossed the doorway and forgotten most of the idea. And lost a bit of the enthusiasm too. Edge - for Django Projects in 2014

So, I created Edge. I believe Edge is a great starting point for Django projects. It comes with Bootstrap assets (even for the admin), basic user sign up flows and a sensible set of default settings. Most importantly, it is built for Django 1.7 and Python 3.4, the latest versions at the time of writing.

As soon as you start your project in edge, you will notice that it has a great looking and functional home page rather than Django’s familiar blue “It Worked!” page. The appearance is much closer to what you expect as a starting point for your app. Check it out yourself in the short demo below.

Edge demo video

Motivations

Things I found missing or inadequate with the default Django project structure

Iconic Omissions

It started with the small things. Doesn’t it always? Every time I noticed a 404 while developing a Django application I had to calm myself down - don’t worry, it is just a missing favicon.

Missing Favicon

I know I would eventually add a favicon in production. But I kind of turned blind to errors on my test server logs. The fix was to add a favicon, of course.

Template and Static paths

Another one of those small things that I would always need to specify to my settings.py. I understand why the paths are not there. But during developing, it would be so much more convenient, if these directories were present and added to settings.

Pathlib

Talking about paths, the awkward os.path.join(BASE_DIR, “templates”) call is needed anymore. Edge uses the new pathlib library in Python 3.4 instead. The new syntax BASE_DIR / “templates” is much more convenient and readable.

Bootstrap

It is 2014 and hardly anybody starts with a blank page (I mean, blank HTML and CSS) anymore. In fact, most people I know start with a minimal Bootstrap 3 template.

There are many good packages for using bootstrap in Django. But edge doesn’t use any of them because it is becomes another dependency that sometimes lags behind the rapid development cycle of Bootstrap. Instead, bootstrap assets have been directly included in the static folder. Updating is now easier, just copy the latest versions into the appropriate paths.

User Authentication

Django has a built-in user model. It is the base for the admin interface and countless other packages. But a simple user sign-up, login and logout workflow needs quite a bit of work to setup.

Django registrations was often used for this but has been inactive for a while. Even though Django allauth is an excellent solution in production, I would hardly use social login in my development environment.

In edge, a simple sign-up and login form has been provided using crispy forms and class based generic views. It does not do email verification or need a dummy mail server setup. But it helps you prototype and build web apps that can be shown to users for early testing.

Admin

“What is this Django Administration?” If only I had a nickel every time someone asked me this. Most projects continue to have their admin interface titled that way even in production.

The admin interface’s appearance also looks quite antiquated. Try opening it on a mobile device. The edge template uses django-admin-bootstrapped to give it a Bootstrap 3 theme. Also, it customises the heading to “MyProject Administration”.

Alternate Project Templates

There are many good project templates already available. I did try using django-twoscoops-project, django-base-template, django-project-skel etc. Some of them did not work properly in Python 3. Others seemed too bloated.

Project templates are a subjective choice. While I prefer a template with all the necessary settings to start focusing on the problem at hand, I find packages like Celery in the bells and whistles category. Using a project template generator like cookiecutter was also something I never preferred.

My solution - edge

Edge has everything what I expect to be in a Django 1.7 and Python 3.4 project. I have used edge in a couple of projects and look forward to using it in my future projects. It is my new baseline.

More details about the features and future plans are on the wiki. The project itself is open source and on Github.

I would love to hear your feedback.

Hi! Welcome to ArunRocks, an odd collection of writeups on programming, travel, gadgets and practically anything under the sun. This state of affairs could be blamed on the ecelectic interests of your host, Arun Ravindran. He loves programming in several languages especially Python.

Posted on:Mon, Sep 22, 2014

Next: ▶  Django Design Patterns and Best Practices Book - Coming Soon

Prev: ◀  Recreating the "Building a Blog in Django" Screencast

Up: ▲  Blog

Don't miss any future posts!

Share on: Twitter, Facebook, Google+

Comments