Quick Start

Usage

Start by creating the architecture of a Django project.

Execute the following line of code inside the root folder of your project:

djpro project YOUR-PROJECT-NAME

Note

Change YOUR-PROJECT-NAME to your project name.

djpro will create a Django project with the following structure:

root/
├── .env.dev
├── .gitignore
├── requirements.txt
└── src/
    ├── bin/
       ├── __init__.py
       └── manage.py
    ├── config/
       ├── .env.conf
       ├── __init__.py
       ├── asgi.py
       ├── settings_base.py
       ├── settings_dev.py
       ├── settings_prod.py
       ├── settings.py
       ├── urls.py
       └── wsgi.py
    ├── modules/
       ├── __init__.py
       └── authentication/
           ├── __init__.py
           ├── models/
              ├── __init__.py
              └── auth_model.py
           ├── serializers/
              ├── __init__.py
              └── login_serializer.py
           ├── urls.py
           └── views/
               ├── __init__.py
               └── login.py
    ├── static/
    ├── tests/
    ├── templates/
    └── utils/
        └── __init__.py

Run your Django project executing the following commands inside the folder src:

pip install -r requirements.txt
djpro man collectstatic
djpro man runserver

Create a new Module

Note

We call modules to the applications contained in your Django project.

You can create a new Module in your existing project executing the following command:

djpro module YOUR-MODULE-NAME

Note

Change YOUR-MODULE-NAME to your Module name.

Note

IMPORTANT: The module subcommand needs to find the src folder. Run the command in the root folder of your project.

You can also add the files you want to be created in your module:

djpro module YOUR-MODULE-NAME -models -views -urls

Note

This command will create the module folder including the models.py, views.py and urls.py files.

root/
└── src/
    └── modules/
        ├── __init__.py
        └── YOUR-MODULE/
            ├── __init__.py
            ├── models/
               ├── __init__.py
               └── models.py
            ├── urls.py
            └── views/
                ├── __init__.py
                └── views.py

See the list of available files:

-models
-views
-serializers
-urls
-forms
-admin
-apps

Run the develop environment locally

djpro man runserver

Note

The man command was created to make it faster and easier to run the manage.py commands in Django. Find out more about its use.


Including API configuration

To include an API configuration (Django Rest Framework) to your project, adds the --api option to the general djpro project creation command:

djpro project YOUR-PROJECT-NAME --api

Note

Change YOUR-PROJECT-NAME to your project name.

djpro will create a Django project including API configuration with the following structure:

root/
├── .env.dev
├── .gitignore
├── requirements.txt
└── src/
    ├── bin/
       ├── __init__.py
       └── manage.py
    ├── config/
       ├── .env.conf
       ├── __init__.py
       ├── asgi.py
       ├── settings_base.py
       ├── settings_dev.py
       ├── settings_prod.py
       ├── settings.py
       ├── urls.py
       └── wsgi.py
    ├── modules/
       ├── __init__.py
       ├── api/
          ├── __init__.py
          ├── models/
             ├── __init__.py
             └── product_model.py
          ├── serializers/
             ├── __init__.py
             └── get_product.py
          ├── urls.py
          └── views/
              ├── __init__.py
              └── get_product.py
       └── authentication/
           ├── __init__.py
           ├── models/
              ├── __init__.py
              └── auth_model.py
           ├── serializers/
              ├── __init__.py
              └── login_serializer.py
           ├── urls.py
           └── views/
               ├── __init__.py
               └── login.py
    ├── static/
    ├── tests/
    ├── templates/
    └── utils/
        └── __init__.py

Note

djpro includes DRF Spectacular already configured for your API documentation. Find your docs configuration in settings_base.

Adding a custom theme for Django Admin Site

To include the Unfold custom theme for Django Admin Site, adds the --unfold option to the general djpro project creation command:

djpro project YOUR-PROJECT-NAME --unfold

Note

Change YOUR-PROJECT-NAME to your project name. Find your unfold configuration in settings_base.

Including Docker configuration

To include Docker configuration to your project, adds the --docker option to the general djpro project creation command:

djpro project YOUR-PROJECT-NAME --docker

Note

Change YOUR-PROJECT-NAME to your project name.

djpro will create a Django project including API configuration with the following structure:

root/
├── .env.dev
├── .env.prod
├── .env.prod.db
├── docker-compose.yml
├── Dockerfile
├── .gitignore
├── requirements.txt
└── src/
    ├── bin/
       ├── __init__.py
       └── manage.py
    ├── config/
       ├── .env.conf
       ├── __init__.py
       ├── asgi.py
       ├── settings_base.py
       ├── settings_dev.py
       ├── settings_prod.py
       ├── settings.py
       ├── urls.py
       └── wsgi.py
    ├── modules/
       ├── __init__.py
       └── authentication/
           ├── __init__.py
           ├── models/
              ├── __init__.py
              └── auth_model.py
           ├── serializers/
              ├── __init__.py
              └── login_serializer.py
           ├── urls.py
           └── views/
               ├── __init__.py
               └── login.py
    ├── static/
    ├── tests/
    ├── templates/
    └── utils/
        └── __init__.py

Note

djpro automatically sets a production environment when the --docker option is run, you can change this by modifying the DJANGO_ENV from prod to dev in config/.env.conf.

IMPORTANT

Before running your Django project using Docker Compose, you have to set your database configuration in .env.prod and .env.prod.db.

Note

.env.prod contains the environment variables needed to run Django. .env.prod.db contains the environment variables to run the Docker db container.

Then you can run the project using the following command:

docker-compose up --build -d

Aplying migrations and collecting static files:

docker-compose exec web python src/bin/manage.py migrate --noinput
docker-compose exec web python src/bin/manage.py collectstatic

Note

If you want to run the project on local using Docker, then you will have to change to ‘True’ the DEBUG mode on settings_prod.py.