Setting up a cloned Django project

One of the things I miss about my JavaScript days is the ease of cloning a repository and getting the dependencies installed. JavaScript projects tend to have a file called package.json which has all the dependencies listed. Simply running $ npm install from the command line was enough to get going.

Despite being two months into my Django journey, simple routines like getting a project set up are far from second nature.

1. Clone the repository

2. Create your own virtual environment

Virtual environments are where dependencies are stored, similar to node_modules in JavaScript. Every time you start your machine, you must activate the virtual environment using source venv/bin/activate.

3. Install your requirements

4. Create a new PostgreSQL database

For this, I’m assuming you already have pgAdmin and postgres installed. Apologies for the lack of detail here.

In your terminal:

Go into pgAdmin, login, and check that the new database exists on the dbserver.

The database credentials to go in your project’s settings.py are the same credentials for pgAdmin.

5. Generate a new secret key

I like using Djecrety to quickly generate secure secret keys.

I also use a .env file to secure my secret key and database credentials. To find out more, check out my post on the topic.

6. Rename the project

Rename the directory that contains settings.py. Do a find all and replace to rename all instances of the new project name.

7. Make your migrations

The only migrations that should appear in each of your app’s migrations folders are called ‘__init__.py’. As we have started a new database, we can delete any existing migrations and migrate from scratch.

In your terminal:

8. Create a new superuser

9. Final checks

Start the development server and ensure everything is running without errors.

That’s it! Now you’re ready to commit your changes to GitHub. Thanks for reading.

Full-stack developer and Django enthusiast. When I can’t find Django tutorials, I write them. https://twitter.com/alcampk

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store