我们从Python开源项目中,提取了以下43个代码示例,用于说明如何使用django.core.wsgi.get_wsgi_application()。
def handle(self, *args, **options): host = options["host"] port = options["port"] print("Prepairing async server ...") loop = asyncio.get_event_loop() wsgi_app = WSGIHandler(get_wsgi_application(), loop=loop) aio_app = websockets.setup(loop=loop) aio_app.router.add_route("*", "/{path_info:.*}", wsgi_app.handle_request) print("Starting async server ...") server = loop.create_server(aio_app.make_handler(), host, port) server = loop.run_until_complete(server) try: print("Server running on {0}:{1}\n CTRL-C to stop.".format(host, port)) loop.run_forever() except KeyboardInterrupt: print("Stopping server...") server.close() loop.run_until_complete(service.wait_closed())
def application(environ, start_response): global _application uwsgi.set_logvar('worker_id', str(uwsgi.worker_id())) if not os.environ.get('DJANGO_SETTINGS_MODULE'): os.environ['DJANGO_SETTINGS_MODULE'] = environ.get('DJANGO_SETTINGS_MODULE', 'settings') if _application is None: try: from django.core.wsgi import get_wsgi_application except ImportError: import django.core.handlers.wsgi _application = django.core.handlers.wsgi.WSGIHandler() else: _application = get_wsgi_application() return _application(environ, start_response)
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() return import_by_path( app_path, error_prefix="WSGI application '%s' could not be loaded; " % app_path )
def setup(self, environ=None): '''Set up the :class:`.WsgiHandler` the first time this middleware is accessed. ''' from django.conf import settings from django.core.wsgi import get_wsgi_application # try: dotted = settings.WSGI_APPLICATION except AttributeError: # pragma nocover dotted = None if dotted: return module_attribute(dotted)() else: app = middleware_in_executor(get_wsgi_application()) return WsgiHandler((wait_for_body_middleware, app))
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()
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 server (runserver); 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])
def application(environ, start_response): """Wrapper for Django's WSGIHandler(). This allows to get values specified by SetEnv in the Apache configuration or interpose other changes to that environment, like installing middleware. """ try: os.environ['POOTLE_SETTINGS'] = environ['POOTLE_SETTINGS'] except KeyError: pass from django.core.wsgi import get_wsgi_application _wsgi_application = get_wsgi_application() return _wsgi_application(environ, start_response)
def loading_app(environ, start_response): global real_app # pass the WSGI environment variables on through to os.environ for var in env_variables_to_pass: os.environ[var] = environ.get(var, '') real_app = get_wsgi_application() return real_app(environ, start_response)
def start(self) -> None: """ When the bus starts, the plugin is also started and we load the Django application. We then mount it on the CherryPy engine for serving as a WSGI application. We let CherryPy serve the application's static files. """ from frontend import settings settings.crawler_settings = self.crawler_settings os.environ['DJANGO_SETTINGS_MODULE'] = self.settings_module from django.core.wsgi import get_wsgi_application def corsstaticdir( section: str, dir: str, root: str = '', match: str = '', content_types: None = None, index: str = '', debug: bool = False ) -> bool: cherrypy.response.headers['Access-Control-Allow-Origin'] = '*' return static.staticdir(section, dir, root, match, content_types, index, debug) cherrypy.tree.graft(self.wsgi_http_logger(get_wsgi_application(), self.crawler_settings)) settings.WORKERS.start_workers(settings.CRAWLER_SETTINGS) tool = cherrypy._cptools.HandlerTool(corsstaticdir) static_handler = tool.handler( section="/", dir=os.path.split(settings.STATIC_ROOT)[1], root=os.path.abspath(os.path.split(settings.STATIC_ROOT)[0]) ) cherrypy.tree.mount(static_handler, settings.STATIC_URL) media_handler = tool.handler( section="/", dir=os.path.split(settings.MEDIA_ROOT)[1], root=os.path.abspath(os.path.split(settings.MEDIA_ROOT)[0]) ) cherrypy.tree.mount(media_handler, settings.MEDIA_URL)
def __init__(self): self.django_handler = get_wsgi_application() self.static_handler = static.Cling(os.path.dirname(os.path.dirname(__file__)))
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])
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()
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'/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()
def load(self): return get_wsgi_application()
def main(): parse_command_line() # Init and get DJANGO application os.environ['DJANGO_SETTINGS_MODULE'] = 'django_app.settings' sys.path.append( os.path.dirname(os.path.realpath(__file__)) + '/django_app') django_wsgi_app = get_wsgi_application() wsgi_django_container = tornado.wsgi.WSGIContainer(django_wsgi_app) # Create TORNADO application, and server tornado_app = tornado.web.Application( [ ('/notif-server', NotifServerListHandler), ('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_django_container)), ]) server = tornado.httpserver.HTTPServer(tornado_app) server.listen(LISTEN_PORT) # Create the NOTIF SERVER handler NotifServerHandler.instance() # Run the whole loop signal.signal(signal.SIGINT, lambda x, y: IOLoop.current().stop()) IOLoop.current().add_callback(lambda: print("Server started on port " + str(LISTEN_PORT))) IOLoop.current().start()