Django prefix on all generated URLs

后端 未结 2 1461
独厮守ぢ
独厮守ぢ 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)
    
    0 讨论(0)
  • 2021-02-14 11:08

    See documentation for FORCE_SCRIPT_NAME:

    https://docs.djangoproject.com/en/dev/ref/settings/#force-script-name

    Set that to be '/app' instead of default of None.

    0 讨论(0)
提交回复
热议问题