本文整理汇总了Python中django.core.wsgi.get_wsgi_application方法的典型用法代码示例。如果您正苦于以下问题:Python wsgi.get_wsgi_application方法的具体用法?Python wsgi.get_wsgi_application怎么用?Python wsgi.get_wsgi_application使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.wsgi
的用法示例。
在下文中一共展示了wsgi.get_wsgi_application方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: django_setup_script
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def django_setup_script():
#################################################################
# TO make this app compatible with Django #
#################################################################
import os
import sys
proj_path = (os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
# venv_python = os.path.join(proj_path, '..', '.venv', 'bin', 'python')
# This is so Django knows where to find stuff.
sys.path.append(os.path.join(proj_path, '..'))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "OnToology.settings")
sys.path.append(proj_path)
# This is so my local_settings.py gets loaded.
os.chdir(proj_path)
# This is so models get loaded.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
#################################################################
示例2: app_with_scout
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def app_with_scout(**settings):
"""
Context manager that simply overrides settings. Unlike the other web
frameworks, Django is a singleton application, so we can't smoothly
uninstall and reinstall scout per test.
"""
settings.setdefault("SCOUT_MONITOR", True)
settings["SCOUT_CORE_AGENT_LAUNCH"] = False
with override_settings(**settings):
# Have to create a new WSGI app each time because the middleware stack
# within it is static
app = get_wsgi_application()
# Run Django checks on first use
if not getattr(app_with_scout, "startup_ran", False):
call_command("migrate")
call_command("check")
app_with_scout.startup_ran = True
yield app
示例3: main
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def main():
os.environ['DJANGO_SETTINGS_MODULE'] = 'demosite.settings' # TODO: edit this
sys.path.append('./demosite') # path to your project if needed
parse_command_line()
wsgi_app = get_wsgi_application()
container = tornado.wsgi.WSGIContainer(wsgi_app)
tornado_app = tornado.web.Application(
[
('/hello-tornado', HelloHandler),
('.*', tornado.web.FallbackHandler, dict(fallback=container)),
])
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
示例4: test_file_wrapper
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def test_file_wrapper(self):
"""
FileResponse uses wsgi.file_wrapper.
"""
class FileWrapper:
def __init__(self, filelike, blksize=8192):
filelike.close()
application = get_wsgi_application()
environ = RequestFactory()._base_environ(
PATH_INFO='/file/',
REQUEST_METHOD='GET',
**{'wsgi.file_wrapper': FileWrapper}
)
response_data = {}
def start_response(status, headers):
response_data['status'] = status
response_data['headers'] = headers
response = application(environ, start_response)
self.assertEqual(response_data['status'], '200 OK')
self.assertIsInstance(response, FileWrapper)
示例5: test_default
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def test_default(self):
"""
If ``WSGI_APPLICATION`` is ``None``, the return value of
``get_wsgi_application`` is returned.
"""
# Mock out get_wsgi_application so we know its return value is used
fake_app = object()
def mock_get_wsgi_app():
return fake_app
from django.core.servers import basehttp
_orig_get_wsgi_app = basehttp.get_wsgi_application
basehttp.get_wsgi_application = mock_get_wsgi_app
try:
app = get_internal_wsgi_application()
self.assertIs(app, fake_app)
finally:
basehttp.get_wsgi_application = _orig_get_wsgi_app
示例6: test_file_wrapper
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def test_file_wrapper(self):
"""
FileResponse uses wsgi.file_wrapper.
"""
class FileWrapper:
def __init__(self, filelike, blksize=8192):
filelike.close()
application = get_wsgi_application()
environ = self.request_factory._base_environ(
PATH_INFO='/file/',
REQUEST_METHOD='GET',
**{'wsgi.file_wrapper': FileWrapper}
)
response_data = {}
def start_response(status, headers):
response_data['status'] = status
response_data['headers'] = headers
response = application(environ, start_response)
self.assertEqual(response_data['status'], '200 OK')
self.assertIsInstance(response, FileWrapper)
示例7: run
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def run():
if not settings.configured:
raise ImproperlyConfigured("You should call configure() after configuration define.")
if _parent_module.__name__ == '__main__':
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
else:
from django.core.wsgi import get_wsgi_application
return get_wsgi_application()
示例8: get_internal_wsgi_application
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def get_internal_wsgi_application():
"""
Loads and returns the WSGI application as configured by the user in
``settings.WSGI_APPLICATION``. With the default ``startproject`` layout,
this will be the ``application`` object in ``projectname/wsgi.py``.
This function, and the ``WSGI_APPLICATION`` setting itself, are only useful
for Django's internal servers (runserver, runfcgi); external WSGI servers
should just be configured to point to the correct application object
directly.
If settings.WSGI_APPLICATION is not set (is ``None``), we just return
whatever ``django.core.wsgi.get_wsgi_application`` returns.
"""
from django.conf import settings
app_path = getattr(settings, 'WSGI_APPLICATION')
if app_path is None:
return get_wsgi_application()
try:
return import_string(app_path)
except ImportError as e:
msg = (
"WSGI application '%(app_path)s' could not be loaded; "
"Error importing module: '%(exception)s'" % ({
'app_path': app_path,
'exception': e,
})
)
six.reraise(ImproperlyConfigured, ImproperlyConfigured(msg),
sys.exc_info()[2])
示例9: runtests
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def runtests():
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings"
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
from django.core.management import call_command
result = call_command('test', 'userapp')
sys.exit(result)
示例10: load
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def load(self):
return get_wsgi_application()
示例11: get_internal_wsgi_application
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def get_internal_wsgi_application():
"""
Loads and returns the WSGI application as configured by the user in
``settings.WSGI_APPLICATION``. With the default ``startproject`` layout,
this will be the ``application`` object in ``projectname/wsgi.py``.
This function, and the ``WSGI_APPLICATION`` setting itself, are only useful
for Django's internal servers (runserver, runfcgi); external WSGI servers
should just be configured to point to the correct application object
directly.
If settings.WSGI_APPLICATION is not set (is ``None``), we just return
whatever ``django.core.wsgi.get_wsgi_application`` returns.
"""
from django.conf import settings
app_path = getattr(settings, 'WSGI_APPLICATION')
if app_path is None:
return get_wsgi_application()
module_name, attr = app_path.rsplit('.', 1)
try:
mod = import_module(module_name)
except ImportError as e:
raise ImproperlyConfigured(
"WSGI application '%s' could not be loaded; "
"could not import module '%s': %s" % (app_path, module_name, e))
try:
app = getattr(mod, attr)
except AttributeError as e:
raise ImproperlyConfigured(
"WSGI application '%s' could not be loaded; "
"can't find '%s' in module '%s': %s"
% (app_path, attr, module_name, e))
return app
示例12: get_django_wsgi
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def get_django_wsgi(settings_module):
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)
import django
if django.VERSION[0] <= 1 and django.VERSION[1] < 7:
# call django.setup only for django <1.7.0
# (because setup already in get_wsgi_application since that)
# https://github.com/django/django/commit/80d74097b4bd7186ad99b6d41d0ed90347a39b21
django.setup()
return get_wsgi_application()
示例13: test_get_wsgi_application
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def test_get_wsgi_application(self):
"""
get_wsgi_application() returns a functioning WSGI callable.
"""
application = get_wsgi_application()
environ = RequestFactory()._base_environ(
PATH_INFO="/",
CONTENT_TYPE="text/html; charset=utf-8",
REQUEST_METHOD="GET"
)
response_data = {}
def start_response(status, headers):
response_data["status"] = status
response_data["headers"] = headers
response = application(environ, start_response)
self.assertEqual(response_data["status"], "200 OK")
self.assertEqual(
set(response_data["headers"]),
{('Content-Length', '12'), ('Content-Type', 'text/html; charset=utf-8')})
self.assertIn(bytes(response), [
b"Content-Length: 12\r\nContent-Type: text/html; charset=utf-8\r\n\r\nHello World!",
b"Content-Type: text/html; charset=utf-8\r\nContent-Length: 12\r\n\r\nHello World!"
])
示例14: test_get_wsgi_application
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def test_get_wsgi_application(self):
"""
get_wsgi_application() returns a functioning WSGI callable.
"""
application = get_wsgi_application()
environ = self.request_factory._base_environ(
PATH_INFO="/",
CONTENT_TYPE="text/html; charset=utf-8",
REQUEST_METHOD="GET"
)
response_data = {}
def start_response(status, headers):
response_data["status"] = status
response_data["headers"] = headers
response = application(environ, start_response)
self.assertEqual(response_data["status"], "200 OK")
self.assertEqual(
set(response_data["headers"]),
{('Content-Length', '12'), ('Content-Type', 'text/html; charset=utf-8')})
self.assertIn(bytes(response), [
b"Content-Length: 12\r\nContent-Type: text/html; charset=utf-8\r\n\r\nHello World!",
b"Content-Type: text/html; charset=utf-8\r\nContent-Length: 12\r\n\r\nHello World!"
])
示例15: main
# 需要导入模块: from django.core import wsgi [as 别名]
# 或者: from django.core.wsgi import get_wsgi_application [as 别名]
def main():
from django.core.wsgi import get_wsgi_application
import tornado.wsgi
wsgi_app = get_wsgi_application()
container = tornado.wsgi.WSGIContainer(wsgi_app)
setting = {
'cookie_secret': 'DFksdfsasdfkasdfFKwlwfsdfsa1204mx',
'template_path': os.path.join(os.path.dirname(__file__), 'templates'),
'static_path': os.path.join(os.path.dirname(__file__), 'static'),
'debug': False,
}
tornado_app = tornado.web.Application(
[
(r'/ws/monitor', MonitorHandler),
(r'/ws/terminal', WebTerminalHandler),
(r'/ws/kill', WebTerminalKillHandler),
(r'/ws/exec', ExecHandler),
(r"/static/(.*)", tornado.web.StaticFileHandler,
dict(path=os.path.join(os.path.dirname(__file__), "static"))),
('.*', tornado.web.FallbackHandler, dict(fallback=container)),
], **setting)
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(options.port, address=IP)
tornado.ioloop.IOLoop.instance().start()