Django

This document provides instructions for working with Django and the CommandK CLI. It explains how to run your Django application and manage secrets effectively using the CommandK CLI.

Prerequisites

Before you begin the integration process, make sure you have the following:

  1. API Access Token: To authenticate your Django application with CommandK, you'll need an API access token. If you haven't obtained one yet, refer to this link for instructions on how to acquire it.

Integration Steps

Follow these steps to integrate CommandK with your Django application:

Step 1: Create a Django Application

If you haven't already created a Django application, you can set up a new project using the Django CLI or any other preferred method. Here, we'll use the Django CLI for demonstration:

  1. Install Django if you haven't already:

    pip install Django
    
  2. Create a new Django project using the following command:

    django-admin startproject my_django_app
    

    Replace my_django_app with your desired project name.

  3. Navigate to the project directory:

    cd my_django_app
    

Step 2: Access Secrets in Your Django Application

Inside your Django application, you can access secrets as environment variables. Open the appropriate file (e.g., settings.py) and add the following code snippet to access an environment variable:

import os
from dotenv import load_dotenv

load_dotenv()

SECRET_KEY = os.getenv('DJANGO_SECRET_KEY')

This code uses the dotenv library to load environment variables and sets the Django secret key as an example.

Running Your Django Application

To run your Django application with the CommandK CLI, you can use the following command:

$ cmdk run <application-name> --environment development -- python manage.py runserver

Replace <application-name> with the actual name of your Django application. This command will execute your Django application, running the development server.

By following these instructions, you can seamlessly integrate the CommandK CLI with your Django application, making it easy to manage secrets and run your application securely.