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.

git clone https://github.com/<username>/<forked-repo>.git
python3 -m venv venvsource venv/bin/activate

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.

pip install -r requirements.txt

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

In your terminal:

$ psql postgres$ CREATE DATABASE databasename$ \connect databasename

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.

settings.py
DATABASES = {‘default’: {‘ENGINE’: ‘django.db.backends.postgresql_psycopg2’,‘NAME’: env(‘DATABASE_NAME’),‘USER’: env(‘DATABASE_USER’),‘PASSWORD’: env(‘DATABASE_PASS’),}}

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.

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

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:

$ python manage.py makemigrations$ python manage.py migrate
python manage.py createsuperuser

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

python manage.py runserver

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