Python django.core.wsgi.get_wsgi_application() Examples
The following are 15
code examples of django.core.wsgi.get_wsgi_application().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.core.wsgi
, or try the search function
.
Example #1
Source File: autoncore.py From OnToology with Apache License 2.0 | 6 votes |
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() #################################################################
Example #2
Source File: test_django.py From scout_apm_python with MIT License | 6 votes |
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
Example #3
Source File: run_tornado.py From django-tornado with MIT License | 6 votes |
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()
Example #4
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #5
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
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
Example #6
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #7
Source File: django_micro.py From django-micro with BSD 2-Clause "Simplified" License | 5 votes |
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()
Example #8
Source File: basehttp.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
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])
Example #9
Source File: runtests.py From django-seo with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #10
Source File: webserver.py From yawn with MIT License | 5 votes |
def load(self): return get_wsgi_application()
Example #11
Source File: basehttp.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
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
Example #12
Source File: django_zappa.py From Zappa with MIT License | 5 votes |
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()
Example #13
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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!" ])
Example #14
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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!" ])
Example #15
Source File: run_server.py From DevOpsCloud with GNU General Public License v2.0 | 5 votes |
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()