Mar 07, 2017

Quickly and Easily Way to Create a Django Application: BeDjango Starter

Pablo Iglesias

@Pypiglesias

BeDjango starter

In the following post we will talk about the starter we have released from BeDjango.  The decisions we have made, the features we have decided to add and some aspects that we would like to emphasize:

Why did we decide to make a starter?

Although starting a project in Django is a fairly quick and easy process, after developing several applications, we realized that we used to invest a certain amount of time in each project to implement similar features (registry, basic views, validations, configuration of libraries ...) Therebefore, we decided to invest that time in making a starter that we could easily reuse ... But the thing went out of hand and we created a fairly complete Django base application.

Architecture

We decided to modify the initial structure of folders and files that gives us django, many of these files are already being used by the community:

 

We would like to point out that we have added a 'logic.py' file where we place all the logic of code, in this way we gain modularity and improve the way we have to perform the tests, doing these directly against code and not only with access to views. We have also been forced to create managers for all the objects of our models.

Main Features

  • Coverage of code over 95% (98% at the time of release)

  • Custom theme based on bootstrap, with custom and responsive components.

  • User control system (1-step or 2-step registration, login, password recovery ..)

  • Modularity of the applications (users, base)

  • Application ready for internationalization

  • Python2/3 compatibility

Packages included

After reviewing several packages that we often use, we decided to include some already preconfigured ones:

  1. Django debug toolbar
  2. Django cachalot
  3. Material design for admin

Utils

We have also decided to put a series of utils that we needed or that we usually use in most projects:

  • Breadcrumbs

  • Password validation via ajax

  • Decorators: group required, ajax required (to protect views), anonymous required (to prevent logged user to visit some views)

  • Regex for password validation

Requirements

Here are the system requirements needed for the starter to work down a distribution Ubuntu 16.04:

  • Git:

sudo apt install git
  • Pip:

sudo apt install python-pip
  • Virtualenv:

sudo pip install virtualenv
  • Python3-dev:

sudo apt install python3-dev

How to use it

# Create virtualenv
virtualenv -p python3 venv

# Activate virtualenv and install Django
source venv/bin/activate
pip install django==1.10

Use django-admin to create the app using the starter
django-admin.py startproject --template=https://github.com/BeDjango/bedjango-starter/archive/master.zip --extension=py,rst,yml {{nameofproject}}

# Install requirements/dev-requirements
cd nameofproject/nameofproject
pip install -r requirements.txt
pip install -r requirements-dev.txt

# Migrate database 
python3 manage.py migrate

# Compile translations
python3 manage.py compilemessages

# To run our project:
python3 manage.py runserver

 

Contribution

We this release we intend to give back some of the knowledge and the tools which are given by the community but with a processing from our side. We don’t expect to create a project itself, however, we open a Github with a code which could be used and personalized by everyone, and moreover, we will be grateful if we receive some feedback as comments (both pros and cons), proposals or contributions. For that this project is licensed under the MIT License

I hope you try it and like it :)!

Leave a comment