Development#

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

  • Install project requirements

  • Set up Docker containers (Postgres and Redis)

  • Configure OpenSearch DSL

  • Run database migrations

  • 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 your Docker containers.

Set up Docker containers#

We use Docker Compose to set up both Postgres and Redis. 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

Configure OpenSearch DSL#

Before running migrations, you need to either configure OpenSearch DSL with proper AWS credentials or remove it from your settings.

To configure OpenSearch DSL, make sure you have the following environment variables set in your .env file:

  • AWS_OPEN_SEARCH_HOST

  • AWS_ACCESS_KEY_ID

  • AWS_SECRET_ACCESS_KEY

  • AWS_OPEN_SEARCH_REGION_NAME

Your settings.py should include this configuration:

OPENSEARCH_DSL = {
    "default": {
        "hosts": AWS_OPEN_SEARCH_HOST,
        "http_auth": AWSV4SignerAuth(
            boto3.Session(
                aws_access_key_id=AWS_ACCESS_KEY_ID,
                aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
            ).get_credentials(),
            AWS_OPEN_SEARCH_REGION_NAME,
            "es",
        ),
        "use_ssl": True,
        "verify_certs": True,
        "connection_class": RequestsHttpConnection,
        "pool_maxsize": 20,
    },
}

If you don’t plan to use OpenSearch, you must:

  1. Remove the OPENSEARCH_DSL setting from your settings.py

  2. Remove 'django_opensearch_dsl' from INSTALLED_APPS in settings.py

Run migrations#

Once you’ve properly configured or removed OpenSearch DSL, you can 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.

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

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.

Install Tailwind dependencies#

To Install Tailwind dependencies head over to the terminal

python src/manage.py tailwind install

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.