Development#

After you have generated your project, there are a few things missing in your development environment to get started:

  • Install project requirements

  • Create and connect a Postgres database

  • Run database migrations

  • Create and connect a Redis instance

  • Set up a Stripe project and product

  • Set up Sign in with Google

  • Install Tailwind dependencies

We will walk you through each step with what we consider the faster approach. If you know how to do it in another way, fell free to deviate.

The first step is to install the project requirements.

Install project requirements#

Open your terminal in the project root

pip install -r requirements.txt

This will install all the requirements to develop, format, lint and write docs for your project.

Next up is setting up Postgres and Redis.

Set up Postgres and Redis instances#

We’ve built Django Rocket having Postgres in mind so we’ll guide you through setting one up. We’ll do it using Docker Compose. If you don’t have Compose installed, go over to Install Compose and then come back.

Your initial project ships with a docker-compose.yml file in the root. Here’s how it looks:

version: "3.1"

services:

   postgres:
      image: postgres:latest
      restart: always
      environment:
         - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
         - POSTGRES_DB=${POSTGRES_DB}
      ports:
         - "5432:5432"

   redis:
      image: bitnami/redis:latest
      restart: always
      environment:
         - ALLOW_EMPTY_PASSWORD=yes
      ports:
         - "6379:6379"

Since Django Rocket also ships with a pre-populated .env file, the POSTGRES_PASSWORD and POSTGRES_DB environment variables have already been set for you. All is left to do is run compose

docker compose up

Now that the database is up we can run the project migrations.

Run migrations#

To run the project migrations, in your terminal

python src/manage.py migrate

Notice we expect the manage.py file to be in the src directory.

Note

For a detailed description of the initial project directory, see Initial project structure.

The final before being able to run your project is setting up Stripe.

Set up Stripe#

For this step, you will need a Stripe account. Once you are registered in Stripe, navigate to the dashboard and click on Developers and in the left sidebar click API keys.

From here, you will create a new secret key. The resulting publishable key and secret key should be stored in your .env under the keys STRIPE_PUBLISHABLE_KEY and STRIPE_SECRET_KEY.

Now navigate to Webhooks and add a webhook endpoint. The URL should be https://<HOST>/billing/stripe/webhook/. Make sure to replace <HOST> with your host.

The final step is to create a product. Navigate to the Products tab. Click on “Add a product” and make sure you select “Recurring” under “Price”. Django Rocket expects your product to be a subscription.

Fill all the information for your product and once you are done hit save. Then collect the price id and set it in your .env under the key STRIPE_PRICE_ID

And that’s it with Stripe. Next is Sign in with Google

Set up Sign in with Google#

Open the Google Developer Console. If you don’t have a developer account sign up for one.

Create a new project for your website. Once you have your project created navigate to APIs & Services, select the Credentials tab and create a new OAuth client ID with Web application application type. Assign the resulting client id and secret to GOOGLE_OAUTH_CLIENT_ID and GOOGLE_OAUTH_CLIENT_SECRET respectively in your .env file.

Add http://localhost and http://localhost:8000 to the Authorized JavaScript origins and http://localhost:8000/login/google/ to Authorized redirect URIs and make sure to hit save.

We’re done with Google. The last step is installing Tailwind dependencies.

Install Tailwind dependencies#

To Install Tailwind dependencies head over to the terminal

python src/manage.py tailwind install

Now you are ready to run your project

Running the project#

There are two processes you need running while developing. The first one watches your styles and writes to your stylesheets to include relevant Tailwind utilities

python src/manage.py tailwind start

The second one is your familiar Django server

python src/manage.py runserver

That’s it for setting up your development environment.