Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frameworks/Python/django/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ database_os = "Linux"
os = "Linux"
orm = "Full"
platform = "WSGI"
webserver = "Meinheld"
webserver = "Gunicorn"
versus = "wsgi"

[socketify-wsgi]
Expand Down Expand Up @@ -56,5 +56,5 @@ database_os = "Linux"
os = "Linux"
orm = "Full"
platform = "WSGI"
webserver = "Meinheld"
webserver = "Gunicorn"
versus = "wsgi"
2 changes: 1 addition & 1 deletion frameworks/Python/django/django-postgresql.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12-bullseye
FROM python:3.13-bullseye

ADD ./ /django

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM pypy:3.9-bullseye
FROM pypy:3.11-slim

ADD ./ /django

WORKDIR /django
RUN apt-get update; apt-get install libuv1 -y
RUN apt-get update; apt-get install libuv1 zlib1g -y
RUN pip install -r /django/requirements-socketify.txt

EXPOSE 8080
Expand Down
8 changes: 5 additions & 3 deletions frameworks/Python/django/django-socketify-wsgi.dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM python:3.10-bullseye
FROM python:3.13-bullseye

ADD ./ /django

WORKDIR /django
RUN apt-get update; apt-get install libuv1 -y
RUN pip install -r /django/requirements-socketify.txt

RUN apt-get update && \
apt-get install gcc g++ make libuv1 zlib1g -y && \
pip install -r /django/requirements-socketify.txt

EXPOSE 8080

Expand Down
2 changes: 1 addition & 1 deletion frameworks/Python/django/django.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12-bullseye
FROM python:3.13-bullseye

ADD ./ /django

Expand Down
64 changes: 32 additions & 32 deletions frameworks/Python/django/hello/hello/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,66 @@

DEBUG = False

SECRET_KEY = '_7mb6#v4yf@qhc(r(zbyh&z_iby-na*7wz&-v6pohsul-d#y5f'
SECRET_KEY = "_7mb6#v4yf@qhc(r(zbyh&z_iby-na*7wz&-v6pohsul-d#y5f"
ADMINS = ()

MANAGERS = ADMINS

_django_db = os.getenv('DJANGO_DB', "")
_django_db = os.getenv("DJANGO_DB", "")

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.' + _django_db, # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'hello_world', # Or path to database file if using sqlite3.
'USER': 'benchmarkdbuser', # Not used with sqlite3.
'PASSWORD': 'benchmarkdbpass', # Not used with sqlite3.
'HOST': 'tfb-database', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
'CONN_MAX_AGE': 30,
"default": {
"ENGINE": "django.db.backends."
+ _django_db, # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
"NAME": "hello_world", # Or path to database file if using sqlite3.
"USER": "benchmarkdbuser", # Not used with sqlite3.
"PASSWORD": "benchmarkdbpass", # Not used with sqlite3.
"HOST": "tfb-database", # Set to empty string for localhost. Not used with sqlite3.
"PORT": "", # Set to empty string for default. Not used with sqlite3.
"CONN_MAX_AGE": 30,
}
}

if not _django_db:
DATABASES = { }
DATABASES = {}

TIME_ZONE = 'America/Chicago'
LANGUAGE_CODE = 'en-us'
TIME_ZONE = "America/Chicago"
LANGUAGE_CODE = "en-us"
USE_I18N = False
USE_L10N = False
USE_TZ = False

MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
MEDIA_ROOT = ""
MEDIA_URL = ""
STATIC_ROOT = ""
STATIC_URL = "/static/"
STATICFILES_DIRS = ()
STATICFILES_FINDERS = ()
MIDDLEWARE = ()

ROOT_URLCONF = 'hello.urls'
WSGI_APPLICATION = 'hello.wsgi.application'
ROOT_URLCONF = "hello.urls"
WSGI_APPLICATION = "hello.wsgi.application"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {},
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {},
},
]

INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.sessions',
'world',
"django.contrib.contenttypes",
"django.contrib.sessions",
"world",
)

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'handlers': {},
'loggers': {},

"version": 1,
"disable_existing_loggers": True,
"handlers": {},
"loggers": {},
}

ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = ["*"]
14 changes: 7 additions & 7 deletions frameworks/Python/django/hello/hello/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.conf.urls import url
from django.urls import path
from world.views import plaintext, json, db, dbs, fortunes, update

urlpatterns = [
url(r'^plaintext$', plaintext),
url(r'^json$', json),
url(r'^db$', db),
url(r'^dbs$', dbs),
url(r'^fortunes$', fortunes),
url(r'^update$', update),
path("plaintext", plaintext),
path("json", json),
path("db", db),
path("dbs", dbs),
path("fortunes", fortunes),
path("update", update),
]
16 changes: 1 addition & 15 deletions frameworks/Python/django/hello/hello/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
"""
WSGI config for hello project.

This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.

Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.

"""
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hello.settings")

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()
4 changes: 2 additions & 2 deletions frameworks/Python/django/hello/world/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class World(models.Model):
randomnumber = models.IntegerField()

class Meta:
db_table = 'world'
db_table = "world"


class Fortune(models.Model):
message = models.CharField(max_length=65535)

class Meta:
db_table = 'fortune'
db_table = "fortune"
36 changes: 17 additions & 19 deletions frameworks/Python/django/hello/world/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import random
from operator import itemgetter
from functools import partial
from ujson import dumps as uj_dumps
from orjson import dumps

from django.http import HttpResponse
from django.http import HttpResponse, StreamingHttpResponse
from django.shortcuts import render

from world.models import World, Fortune
Expand All @@ -14,7 +14,7 @@

def _get_queries(request):
try:
queries = int(request.GET.get('queries', 1))
queries = int(request.GET.get("queries", 1))
except Exception:
queries = 1
if queries < 1:
Expand All @@ -25,22 +25,18 @@ def _get_queries(request):


def plaintext(request):
return HttpResponse("Hello, World!", content_type="text/plain")
return StreamingHttpResponse("Hello, World!", content_type="text/plain")


def json(request):
return HttpResponse(
uj_dumps({"message": "Hello, World!"}),
content_type="application/json"
)
dumps({"message": "Hello, World!"}), content_type="application/json"
)


def db(request):
r = _random_int()
world = uj_dumps({
'id': r,
'randomNumber': World.objects.get(id=r).randomnumber
})
world = dumps({"id": r, "randomNumber": World.objects.get(id=r).randomnumber})
return HttpResponse(world, content_type="application/json")


Expand All @@ -49,18 +45,19 @@ def dbs(request):

def caller(input_):
int_ = _random_int()
return {'id': int_, 'randomNumber': World.objects.get(id=int_).randomnumber}
return {"id": int_, "randomNumber": World.objects.get(id=int_).randomnumber}

worlds = tuple(map(caller, range(queries)))

return HttpResponse(uj_dumps(worlds), content_type="application/json")
return HttpResponse(dumps(worlds), content_type="application/json")


def fortunes(request):
fortunes = list(Fortune.objects.values('id', 'message'))
fortunes.append({"id": 0, 'message': "Additional fortune added at request time."})
fortunes.sort(key=itemgetter('message'))
fortunes = list(Fortune.objects.values("id", "message"))
fortunes.append({"id": 0, "message": "Additional fortune added at request time."})
fortunes.sort(key=itemgetter("message"))

return render(request, 'fortunes.html', {'fortunes': fortunes})
return render(request, "fortunes.html", {"fortunes": fortunes})


def update(request):
Expand All @@ -70,7 +67,8 @@ def caller(input_):
w = World.objects.get(id=_random_int())
w.randomnumber = _random_int()
w.save()
return {'id': w.id, 'randomNumber': w.randomnumber}
return {"id": w.id, "randomNumber": w.randomnumber}

worlds = tuple(map(caller, range(queries)))

return HttpResponse(uj_dumps(worlds), content_type="application/json")
return HttpResponse(dumps(worlds), content_type="application/json")
5 changes: 2 additions & 3 deletions frameworks/Python/django/requirements-gunicorn.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-r requirements.txt
greenlet==3.1.1
gunicorn==21.2.0
gevent==24.10.2

gunicorn==23.0.0
3 changes: 2 additions & 1 deletion frameworks/Python/django/requirements-socketify.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-r requirements.txt
git+https://github.com/cirospaciari/socketify.py.git@main#socketify

socketify==0.0.31
10 changes: 5 additions & 5 deletions frameworks/Python/django/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Django==3.2.25
mysqlclient==2.2.6
psycopg2==2.9.9; implementation_name=='cpython'
pytz==2023.2
ujson==5.8.0
Django==5.2.6
mysqlclient==2.2.7
psycopg2-binary==2.9.10
pytz==2025.2
orjson==3.11.3
Loading