This is not an article about setting up a Cookiecutter Django project the right way. It’s about creating a new project and fast forwarding to a state where you can start writing code.
Here’s the minimal and most lazy way to start running a brand-new Cookiecutter Django project, and start coding right away. No need to run Docker, no need to setup external databases. Just start a project and start building.
A word of caution
This instruction is only meant to be used when starting out with a new project It’s great to be lazy - until you should know and do better. Only use this approach for new projects on which you’re hacking by yourself.
As soon as a team is involved, and you need to collaborate (and later deploy), it makes sense to approach this topic with diligence and attention to detail.
Prerequisites
You’ll need to have Python 3 installed - here’s my preferred way to setup Python 3.6 do so on Ubuntu 16.04.
Once you have Python 3 in place, you should install the Cookiecutter package on your system.
Start a new project
Just follow the instructions described in the usage docs. It boils down to running the following command:
$ cookiecutter https://github.com/pydanny/cookiecutter-django
Enter sensible answers to the questions asked, and you’ll be good to go. If you’re not sure whether you need a certain part, you probably can skip it. The defaults are great!
If you want to add something later, that’s fine. It might be a bit more work than selecting it right away, but not impossible.
Setup the project
Alright, the project folder is created and it’s filled with useful files. What now?
Now you need to create a new virtual environment for the project so you have a nice, clean place to work. I like to use virtualenvwrapper, but that’s a tool you don’t really need. Just very convenient in the long run.
Once you have your virtualenv set up, install local dependencies of the project.
$ pip install -r requirements/local.txt
We’re almost there!
This is where you would start tinkering with Docker, or start installing PostgreSQL. But you don’t have to, remember?
Simply set an environment variable to use an SQLite database:
$ export DATABASE_URL="sqlite:///db.sqlite"
This will make Django write data to a db.sqlite
file in the project’s
root folder.
You’re all set! Now you can run the initial management commands and run the dev server
$ python manage.py migrate
$ python manage.py createsuperuser
$ python manage.py runserver
Next steps
The dev server is running, and you can start coding! Mission accomplished.
Once you need to take a break from working with the Django project, or find out something’s missing. There’s all kinds of things you could improve, if you feel the need.
The first would be, to make sure you don’t have to set the env variable manually each time you have a new terminal session. Either put it into the postactivate script of your virtualenv or use dotenv.
Sometime before you consider deploying your new app, you’ll want to switch from SQLite to PostgreSQL, so you have dev and production parity in that regard.