From 288ffaea6eec30aaf1f83d9adc754ed07d1fa6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marwan=20Rabb=C3=A2a?= Date: Tue, 20 Feb 2018 09:11:18 +0100 Subject: [PATCH] Add django (#120) * add a simple example * add launcher for django * launch django using python group * Avoid versioning npm locks (#122) * npm lock file are json one, not using lock extension * remove already versionned npm lock files * update: 20180217 * fix * fix --- Makefile | 8 ++- python/django/app/__init__.py | 0 python/django/app/urls.py | 9 +++ python/django/app/views.py | 13 ++++ python/django/app/wsgi.py | 16 +++++ python/django/requirements.txt | 2 + python/django/server_python_django | 1 + python/django/settings.py | 105 +++++++++++++++++++++++++++++ tools/src/benchmarker.cr | 10 ++- 9 files changed, 157 insertions(+), 7 deletions(-) create mode 100644 python/django/app/__init__.py create mode 100644 python/django/app/urls.py create mode 100644 python/django/app/views.py create mode 100644 python/django/app/wsgi.py create mode 100644 python/django/requirements.txt create mode 100755 python/django/server_python_django create mode 100644 python/django/settings.py diff --git a/Makefile b/Makefile index a87b04a0451..88306c42de5 100644 --- a/Makefile +++ b/Makefile @@ -182,7 +182,7 @@ aspnetcore: ln -s -f ../csharp/aspnetcore/server_csharp_aspnetcore bin/. # --- Python --- -python: sanic japronto flask +python: sanic japronto flask django # Sanic sanic: @@ -199,6 +199,12 @@ flask: cd python/flask; pip3 install -r requirements.txt; chmod +x server_python_flask.py ln -s -f ../python/flask/server_python_flask.py bin/server_python_flask +# Django +django: + cd python/django; pip3 install -r requirements.txt --user + ln -s -f ../python/django/server_python_django bin/server_python_django + + # --- Nim --- nim: jester diff --git a/python/django/app/__init__.py b/python/django/app/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/python/django/app/urls.py b/python/django/app/urls.py new file mode 100644 index 00000000000..3fe690d3fb6 --- /dev/null +++ b/python/django/app/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path(r'', views.index), + path(r'user/', views.get_user), + path(r'user', views.create_user), +] diff --git a/python/django/app/views.py b/python/django/app/views.py new file mode 100644 index 00000000000..d8c1611a4b0 --- /dev/null +++ b/python/django/app/views.py @@ -0,0 +1,13 @@ +from django.shortcuts import render +from django.http import HttpResponse +from django.views.decorators.csrf import csrf_exempt + +def index(request): + return HttpResponse(status=200) + +def get_user(request, id): + return HttpResponse(id) + +@csrf_exempt +def create_user(request): + return HttpResponse(status=200) diff --git a/python/django/app/wsgi.py b/python/django/app/wsgi.py new file mode 100644 index 00000000000..ffbf6bd149e --- /dev/null +++ b/python/django/app/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for bl project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") + +application = get_wsgi_application() diff --git a/python/django/requirements.txt b/python/django/requirements.txt new file mode 100644 index 00000000000..13833253f0c --- /dev/null +++ b/python/django/requirements.txt @@ -0,0 +1,2 @@ +django +gunicorn diff --git a/python/django/server_python_django b/python/django/server_python_django new file mode 100755 index 00000000000..9bfca163f5d --- /dev/null +++ b/python/django/server_python_django @@ -0,0 +1 @@ +cd python/django;gunicorn app.wsgi --bind 127.0.0.1:3000 diff --git a/python/django/settings.py b/python/django/settings.py new file mode 100644 index 00000000000..87d9076c185 --- /dev/null +++ b/python/django/settings.py @@ -0,0 +1,105 @@ +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '3f51&0k++@_2u24_v@f)_-n7a0y&hc8^wmru)q^_flty9%!@er' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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 = 'app.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', + ], + }, + }, +] + +WSGI_APPLICATION = 'app.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/1.11/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.11/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/tools/src/benchmarker.cr b/tools/src/benchmarker.cr index 4c0cec09a3f..b1105b7536f 100644 --- a/tools/src/benchmarker.cr +++ b/tools/src/benchmarker.cr @@ -58,12 +58,8 @@ LANGS = [ {lang: "python", targets: [ {name: "sanic", repo: "channelcat/sanic"}, {name: "japronto", repo: "squeaky-pl/japronto"}, - # Sorry, it's still not working - # For debugging, try; (it will be failed) - # ``` - # ./bin/benchmarker flast - # ``` - # {name: "flask", repo: "pallets/flask"}, + {name: "flask", repo: "pallets/flask"}, + {name: "django", repo: "django/django"}, ]}, {lang: "nim", targets: [ {name: "jester", repo: "dom96/jester"}, @@ -96,6 +92,8 @@ class ExecServer # Since ruby's frameworks are running on puma, we have to kill the independent process if @target.lang == "ruby" kill_proc("puma") + elsif @target.lang == "python" + kill_proc("gunicorn") elsif @target.lang == "node" kill_proc("node") elsif @target.name == "plug"