Django Cookiecutter: The How-To's

Before this discussion, let me ask you this. How do you start structuring your Django project? Well for me, this is the best standard that is much available to start off a Django project. Django cookiecutter. The Django Cookiecutter created by Pydanny allow us to create a Django application with a great structure and best practices in no time.  

The Django Cookiecutter created by Pydanny allow us to create a Django application with a great structure and best practices in no time. Pydanny is run by two technical couple who wrote an ice-cream themed book series on two scoops of Django

Django developers may be familiar with the startproject command, which initializes the directory structure and required files for a bare-bones Django project. While this is fine when you're just learning Django for the first time, it's not great for a real production app. Cookiecutter takes care of a lot of standard tasks for you, including installing software dependencies, setting up testing files, and including and organizing common libraries like Bootstrap and AngularJS. It also generates a software license and a README.

Installation is easy as 1, 2, 3. I assumed you already have cookiecutter installed based on the previous blog on Cookiecutter. If you haven’t read that, please do so. Anyway, moving forward, run this within your desired directory: cookiecutter https://github.com/pydanny/cookiecutter-django.

Here are some of the items being installed in your virtual environment after using Django cookiecutter

  • whitenoise

    • With a couple of lines of config WhiteNoise allows your web app to serve its own static files, making it a self-contained unit that can be deployed anywhere without relying on nginx, Amazon S3 or any other external service. (Especially useful on Heroku, OpenShift and other PaaS providers.)

  • celery

    • Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well.

  • mailhog

    • Whether to use MailHog. MailHog is a tool that simulates email receiving for development purposes. It runs a simple SMTP server which catches any message sent to it. Messages are displayed in a web interface which runs at http://localhost:8025/ You need to download the MailHog executable for your operating system, see the ‘Developing Locally’ docs for instructions.

  • Sentry

    • Whether to use Sentry to log errors from your project.

  • windows

    • Whether you’ll be developing on Windows.

  • use_python

    • By default, the Python code generated will be for Python 3.x. But if you answer y here, it will be legacy Python 2.7 code.

Just a heads up, as of the Cookiecutter 0.7.0 release:

  • Whenever you generate a project with a cookiecutter, the resulting project is output to your current directory.

  • Your cloned cookiecutters are stored by default in your ~/.cookiecutters/ directory (or Windows equivalent). The location is configurable: see advanced_usage for details.

That’s it! You can now start doing awesome Django application using Django cookiecutter. Enjoy!

Blog Posts by Nikko Comidoy