https://github.com/yoonge/conduit-drf
Exemplary back-end realworld application (called Conduit) in Python, built with Django + DRF + MySQL + MySQLClient + SimpleJWT, managed by PDM.
https://github.com/yoonge/conduit-drf
api back-end backend conduit demo django djangorestframework drf example jwt mysql mysqlclient pdm python realworld restful simplejwt
Last synced: 2 months ago
JSON representation
Exemplary back-end realworld application (called Conduit) in Python, built with Django + DRF + MySQL + MySQLClient + SimpleJWT, managed by PDM.
- Host: GitHub
- URL: https://github.com/yoonge/conduit-drf
- Owner: yoonge
- License: mit
- Created: 2024-05-04T14:29:11.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-02T15:07:00.000Z (12 months ago)
- Last Synced: 2025-02-03T19:16:36.420Z (4 months ago)
- Topics: api, back-end, backend, conduit, demo, django, djangorestframework, drf, example, jwt, mysql, mysqlclient, pdm, python, realworld, restful, simplejwt
- Language: Python
- Homepage:
- Size: 86.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ⌨️ Conduit DRF (Django REST Framework)
 [](./LICENSE)    
## 💡 Introduction
Realworld: "The mother of all demo apps" — Exemplary back-end Medium.com clone (called [Conduit](https://github.com/yoonge/conduit-drf)) in Python, built with Django + DRF + MySQL + MySQLClient + SimpleJWT.

## 🔰 Getting Started
```sh
$ git clone https://github.com/yoonge/conduit-drf.git$ cd conduit-django-ssr
# Activate the virtual environment
$ source ./.venv/bin/activate # MacOS
$ ./.venv/Scripts/activate # Windows$ pdm install
$ pdm start
# open anthoer terminal
$ source ./.venv/bin/activate$ pdm makemigrations
$ pdm migrate
$ pdm createsuperuser
```And then, open your browser and visit http://localhost:8000/api/
## 📄 License
Conduit DRF is [MIT-licensed](./LICENSE).
---
## 🏗️ Scaffold
```sh
$ pip install pdm$ mkdir conduit-drf && cd conduit-drf
$ pdm init django
# Activate the virtual environment
$ source ./.venv/bin/activate # MacOS
$ ./.venv/Scripts/activate # Windows$ py manage.py startapp api
$ pdm add djangorestframework, djangorestframework-simplejwt, mysqlclient
```## ⚙️ `settings.py`
```py
# Application definitionINSTALLED_APPS = [
# "django.contrib.admin",
# "django.contrib.auth",
# "django.contrib.contenttypes",
# "django.contrib.sessions",
# "django.contrib.messages",
"django.contrib.staticfiles",
"rest_framework",
"rest_framework_simplejwt",
"api",
]MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
# "django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
# "django.middleware.csrf.CsrfViewMiddleware",
# "django.contrib.auth.middleware.AuthenticationMiddleware",
# "django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]ROOT_URLCONF = "conduit_drf.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
# "django.contrib.auth.context_processors.auth",
# "django.contrib.messages.context_processors.messages",
],
},
},
]# ...
# LANGUAGE_CODE = "zh-hans"
TIME_ZONE = "Asia/Shanghai"
# ...
AUTH_USER_MODEL = "api.User"
LOGIN_REDIRECT_URL = "/api/"
LOGOUT_REDIRECT_URL = "/api/"# APPEND_SLASH = False
# SILENCED_SYSTEM_CHECKS = ['urls.W002']NON_FIELD_ERRORS_KEY = "custom_errors"
# REST framework
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_simplejwt.authentication.JWTAuthentication",
"rest_framework.authentication.SessionAuthentication",
),
"DEFAULT_PAGINATION_CLASS": "api.utils.pagination.CustomPagination",
"DEFAULT_PERMISSION_CLASSES": (
"rest_framework.permissions.IsAuthenticated",
),
"UNAUTHENTICATED_USER": None,
}# DRF Simple JWT
SIMPLE_JWT = {
"USER_ID_FIELD": "_id",
"TOKEN_OBTAIN_SERIALIZER": "api.serializers.MyTokenObtainPairSerializer",
}
```