By Emmanuelle Delescolle
Source FreeIMG
Source WikiMedia
Poor documentation of most libraries
A lot of Python packages are well documented
Little sense of community
Friendly Python community
Rails was the "reference"
Many Python web frameworks to get inspiration from
Lack of tools "in the spirit of Django"
Django inspired many libraries
Server-rendered-pages was the main thing to have in mind
Rest API's and websockets have become primary concerns
Source pixabay
django-admin startproject splendid
./manage.py startapp core
cookiecutter cordy_project
cookiecutter cordy_app
class Deck(Model):
level = models.IntegerField()
cards = JSONField()
Deck.objects.filter(level=2)
class Deck(Model):
level = pw.IntegerField()
cards = JSONField()
Deck.select().filter(level=2)
<p>{{object.level}}</p>
{%if object.level == 3 %}
<span>Many points</span>
{%endif%}
<p>{{object.level}}</p>
{%if object.level == 3 %}
<span>Many points</span>
{%endif%}
from django.conf import settings
print(settings.SOME_VAR)
from simple_settings import settings
print(settings.SOME_VAR)
from django.urls import path
from myapp.views import InfoView
urlpatterns = [
path('deck/<uuid:uuid>/info', InfoView.as_view(), name='infos'),
]
from route.route import Route
url_map = [
Route('infos', '/deck/{id}/info', controller='myapp.DeckViewSet', action='info'),
]
from rest_framework import serializers
class CreateUserSerializer(serializers.Serializer):
username = serializers.CharField(required=True)
password = serializers.CharField(required=True)
from marshmallow import fields, Schema
class UserCreateSerializer(Schema):
username = fields.String()
password = fields.String()
if request.method == 'GET':
do_something()
elif request.method == 'POST':
do_something_else()
return HttpResponse("Here's the text of the Web page.")
if request.method == 'GET':
do_something()
elif request.method == 'POST':
do_something_else()
return Response(text="Here's the text of the Web page."')
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('poll_ids', nargs='+', type=int)
def handle(self, *args, **options):
# do something
@click.command()
@click.argument('poll_ids', nargs=-1)
def hello(poll_ids=()):
# do something
IE: fancy name function wrappers
class SimpleMiddleware:
# Same as WSGI middleware
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
# do something with request
response = self.get_response(request)
# do something with response
return response
# Fancy
def process_view(self, request, view_func, view_args, view_kwargs):
pass
def process_exception(self, request, exception):
pass
def process_template_response(self, request, response):
pass
def application(env, start_response):
uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', ''))
while True:
msg = uwsgi.websocket_recv()
uwsgi.websocket_send(msg)
Source flickr
Source WikiMedia
} ->
Copy from Django
->
->
Use "regular" form handling
Cordy
Belgian actress and singer
Léonie, Baroness Cooreman, known by the stage name Annie Cordy, was a Belgian actress and singer. She appeared in more than 50 films from 1954. King Albert II of Belgium bestowed upon her the title of Baroness in recognition for her life's achievements.
Cordy is a way to rope-in all the libraries and components mentioned before.
It is a thought experiment
Hopefully it can serve as inspiration for the future of Django
from cordy.auth.models import BaseUser, Group
from cordy.db.models import Model
import peewee as pw
class ToDo(Model):
description = pw.TextField()
is_done = pw.BooleanField(null=True)
class User(BaseUser):
groups = pw.ManyToManyField(Group, backref='users')
UserGroup = User.groups.get_through_model()
class Controller(CordyController):
@action(needs_id=False)
def index(self):
return HTMLResponse(content="<h1>Hello World</h1>")
class ToDoViewSet(CRUDViewSet):
Model = ToDo
pagination_class = PageNumberPagination
page_size = 2
filter_fields = ['is_done']
search_fields = ['description', ]
@authorize_with(AllowAll)
class ToDoHTML(HTMLCRUDViewSet):
Model = ToDo
@action(needs_id=False)
@login_required()
def index(self, *args, **kwargs):
return super().index(*args, **kwargs)
class WSController(CordyWSController):
def on_connect(self):
print('WS Connect')
def on_receive(self, data):
self.send(data['data'])
def on_message(self, message):
print('Received message:', message)
def on_disconnect(self):
print('WS Disconnected')
from routes.route import Route
from cordy.auth.controllers import AuthController
from cordy.crud.controllers import OpenAPIView
from cordy.utils import include
from myapp.controllers import Controller, ToDoViewSet, Routes, ToDoHTML
url_map = [
*Controller.get_routes(prefix=''),
*Routes.get_routes(),
include(ToDoViewSet.get_routes(), '/api/v1'),
include(OpenAPIView.get_routes(prefix='v1', path='/api/v1/'), '/apidocs'),
include(ToDoHTML.get_routes(prefix='todo'), ''),
include(AuthController.get_routes(prefix='auth'), '/api'),
Route('websocket', '/ws/', controller='myapp.WSController', action='connect'),
Route('static', "/public/{path_info:.*}", controller='cordy.base.StaticFiles', action='serve'),
]
People involved in Django are already involved in those libraries
Loss of agency (dependent on library maintainers)
By their existence, these libraries prove their is a want for "Django bits and pieces"
Maintaining Django as a whole is easier
ReWrite needed
Resources dedicated to Django could benefit a wider community
Possible loss of backward compatibility
Overall less work needed
Root
Shell
Curry