Skip to content

Commit

Permalink
Add django (#120)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
waghanza authored and tbrand committed Feb 20, 2018
1 parent 0032368 commit 288ffae
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 7 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
Empty file added python/django/app/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions python/django/app/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from . import views

urlpatterns = [
path(r'', views.index),
path(r'user/<int:id>', views.get_user),
path(r'user', views.create_user),
]
13 changes: 13 additions & 0 deletions python/django/app/views.py
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 16 additions & 0 deletions python/django/app/wsgi.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions python/django/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
django
gunicorn
1 change: 1 addition & 0 deletions python/django/server_python_django
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cd python/django;gunicorn app.wsgi --bind 127.0.0.1:3000
105 changes: 105 additions & 0 deletions python/django/settings.py
Original file line number Diff line number Diff line change
@@ -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/'
10 changes: 4 additions & 6 deletions tools/src/benchmarker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 288ffae

Please sign in to comment.