Last update on .

Cookiecutter Django by Daniel Greenfeld is a framework that allows a quick start for setting up production-ready Django projects quickly. In this article, we'll detail what the set up steps are on a Windows machine.

Daniel Greenfeld, one of the co-authors of Two Scoops of Django, has created an open-source framework for getting Django projects up and running very quickly. It is called Cookiecutter Django and does a great job of getting your environment set up and ready to go using Python 3.6.

The purpose of this article is document in detail the steps you take to get everything ready all in one place.

Preparation

First install Cookiecutter using pip.

$ pip install "cookiecutter>=1.6.0"

Now run it against this repository:

$ cookiecutter https://github.com/pydanny/cookiecutter-django

You will be prompted to answer questions about the project and the tools you will be using in your project. Make sure that you change the name for the project, author, email, etc.

Change directories to the new directory you just created to start customizing.

$ ls <slugname>

Set Up Your Git Repository

Create a git repo and push it there (changing the names to match your own):

$ git init
$ git add .
$ git commit -m "first commit"
$ git remote add origin git@github.com:yourname/yourrepo.git
$ git push -u origin master

Set Up the Python Development Environment

Create the virtual environment and activate it. (Commands below are for Windows.)

$ python -m venv venv
$ source ./venv/Scripts/activate
$ python -m pip install --upgrade pip

Install development requirements. (You may need to install Pillow and psycopg manually.)

$ pip install -r requirements/local.txt

Create a new PostgreSQL database. If using a different user name, add the --username option (shown below); otherwise, the database will be created using the default username that you are logged in as. (For more information on database options in PostgreSQL, click here.

$ createdb <project_slug_name> --username=<username>

Update the DATABASE_URL default in the base.py settings file by adding the user and user password

DATABASES = {
    'default': env.db('DATABASE_URL', default='postgres://username:user_password@localhost:5432/db_name'),
    }

Apply migrations.

$ python manage.py migrate

Create a superuser.

$ python manage.py createsuperuser

Run the Django server.

$ python manage.py runserver

Set Up Node Development for Live Reloading

LiveReloadmonitors changes in the file system so that any time you save a file, the browser is refreshed and shows those updates. To use this functionality, you must have nodejs installed. Then install the additional packages needed from NPM.

In the project root run install the node packages listed in the package.json file.

$ npm install

Once everything has installed, run the command to open the site. Now, every time you make a change to your HTML, SaaS or JS files, the site will automatically update to show those changes.

$ npm run dev

Now you are set to go and can begin configuring your models, views, templates, etc. on your new project.

Happy Coding!

Additional Information about Entry

Comments

No comments yet.

Post your comment