Django prefix on all generated URLs

后端 未结 2 1458
独厮守ぢ
独厮守ぢ 2021-02-14 10:21

My proxy (nginx public port 80) to django (gunicorn wsgi localhost port 8000) strips off the path to the application \"/app\" so requests for http://server/app/hello

2条回答
  •  生来不讨喜
    2021-02-14 11:04

    Simplest way is to write your own wsgi dispatcher, like one below

    def application(environ, request_response):
      # do whatever you want with path
    
      sys.path.append(path_to_django_project)
      os.environ['DJANGO_SETTINGS_MODULE'] = 'proj_name.settings'
    
      # pass control to django
      import django.core.handlers.wsgi
      app_entry_point = django.core.handlers.wsgi.WSGIHandler()
      return app_entry_point(environ,request_response)
    

提交回复
热议问题