Django
Integration with Django.
Setup
Set up Django project.
Create a file (generally called
pyotconf.py
) under any project module.Configure the models and pipelines inside this file.
Add
pyot
to theINSTALLED_APPS
of the projectsettings.py
file.Add the file path of the configuration file to a new
settings.py
variablePYOT_CONFS
(list or iterable).
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pyot',
]
PYOT_CONFS = ['mysite.pyotconf.py']
Views
If wsgi is used (unsure about asgi), it is forced to run async views in threads, make sure to use resource managers for graceful handling of resources, refer to Cores -> Resources.
from django.views import View
from asgiref.sync import async_to_sync
from pyot.core.resources import resource_manager
@resource_manager.as_decorator
async def function_based_view_using_decorator(request):
...
async def function_based_view_using_context_manager(request):
async with resource_manager():
...
class ClassBasedDecoratedView(View):
@resource_manager.as_decorator
async def get(self, request):
...
class ClassBasedContextManagedView(View):
async def get(request):
async with resource_manager():
...
Last updated