My WSGI Interface implementation
- Python 3.6
$ make
To run built-in test framework app type:
$ gwsgi
To run your own application you have two options:
- Provide config.ini filepath
$ gwsgi --ini /config.ini
- Or provide directory and module variables
$ gwsgi --chdir /opt/project --module project_name.app
For more information type: $ gwsgi -h
Test built-in framework by such requests:
- http://localhost:8051/
- http://localhost:8051/hello/?name=username
- http://localhost:8051/hello/alex/page1
[gwsgi]
chdir = /opt/project
module = project_name.app
host = localhost
port = 8051
threading = false
processing = false
wsgiref = false
from grin_wsgi.framework.http import HttpResponse
from grin_wsgi.framework.app import Project
project = Project()
app = project.register_app(__name__)
@app.route(r'hello/(.+)$', required_methods=['GET'])
@app.route(r'hello/<str:name>/page<int:page>$', required_methods=['GET'])
def hello(request, **kwargs):
name = kwargs.get('name', request.data.get('name', 'Anonymus'))
page = kwargs.get('page')
html = f'Hello, {name}!'
if page is not None:
html += f' You are on the {page} page.'
return HttpResponse(html)
Note: you should always create project = Project()
variable to define your project. Each new Application should be registered through the project
var.
$ PYTHONPATH=. pytest