Boilerplate for quickly creating a DRF projects and apps.
- Pre-configured with logging, swagger, global access conditions, and JWT authentication.
- App template including signals, urls (with router), serializer, and background tasks.
- Users application implementing custom model, serializer, and view set for user (with history).
- Included PyCharm run configurations for
runserver
,shell
, and mockup data export/import.
- PIP Requirements: https://git.io/JOM5l (optional)
- Project Template: https://git.io/JOM5X
- App Template: https://git.io/JOM5y
- Django (3.1, 3.2)
- ipython
- django-debug-toolbar
- django-cors-headers
- django-simple-history
- django-background-tasks
- djangorestframework
- django-filter
- drf-yasg
- djangorestframework-simplejwt
- drf-access-policy
Create a new folder with the name of your Django project, open a terminal in it and run:
Note: You may want to install the pip packages manually to install specific versions of packages.
Click to expand
pip install django ipython docutils django-debug-toolbar django-cors-headers django-simple-history django-background-tasks djangorestframwrork django-filter drf-yasg djangorestframework-simplejwt drf-access-policy
$ git init
$ python -m venv venv
$ ./venv/Scripts/activate
(venv) $ pip install -r https://git.io/JOM5l
(venv) $ django-admin startproject <project_name> . --template https://git.io/JOM5X
(venv) $ py manage.py migrate
Notice: It is advised to create a
requirements.txt
file to store your project's dependencies.
Click to expand
pip freeze > requirements.txt
Notice: To use the included PyCharm run configurations, rename the
_run
folder to.run
.
Click to expand
mv _run .run
Open a terminal, activated with the project's virtual environment and run:
(venv) $ py manage.py startapp <app_name> --template https://git.io/JOM5y
Add your app to the INSTALLED_APPS
setting in your settings.py
file:
INSTALLED_APPS = [
# Project apps
"<app_name>",
]
Include the app's router in your projects urls.py
file:
urlpatterns = [
# Project app routers
path("<app_name>/", include("<app_name>.urls")),
]
This boilerplate includes PyCharm Run Configurations for:
- runserver - Starts a lightweight Web server for development and also serves static files.
- process_tasks - Run tasks that are scheduled to run on the queue.
- shell - Runs a Python interactive interpreter (using IPython, with PyCharm debug mode).
- export mockup - Export model data to
mockup.json
usingdumpdata
(used for mockup data). - import mockup - Import model data from
mockup.json
usingloaddata
(used for mockup data). - test - Discover and run tests in your project.