'why does my django site url reveal the directory path on the server?
I am deploying a django site for the first time to a cpanel server with phusion passenger on cloudlinux and i have discovered a weird phenomenon that can't be normal.
When I go to the site homepage it comes up as expected and when I click on any link the page loads fine but the url displays the full directory path to the app location on the server.
So, for example, rather than -
https://website.net/django_app
I get -
https://website.net/home/userdir/django_site/django_app
I don't even know where to begin to troubleshoot this as all the deployment settings were straightforward but I have clearly done something wrong somewhere.
Here is my passenger_wsgi.py file which I got from this site (https://www.a2hosting.co.uk/kb/developer-corner/python/installing-and-configuring-django-on-linux-shared-hosting) as the cpanel automatically generated passenger_wsgi did not work ;
1 import os
2 import sys
3
4 import django.core.handlers.wsgi
5 from django.core.wsgi import get_wsgi_application
6
7 # Set up paths and environment variables
8 sys.path.append(os.getcwd())
9 os.environ['DJANGO_SETTINGS_MODULE'] = 'django_site.deployment_settings'
10
11 # Set script name for the PATH_INFO fix below
12 SCRIPT_NAME = os.getcwd()
13
14 class PassengerPathInfoFix(object):
15 """
16 Sets PATH_INFO from REQUEST_URI because Passenger doesn't provide it.
17 """
18 def __init__(self, app):
19 self.app = app
20
21 def __call__(self, environ, start_response):
22 from urllib.parse import unquote
23 environ['SCRIPT_NAME'] = SCRIPT_NAME
24 request_uri = unquote(environ['REQUEST_URI'])
25 script_name = unquote(environ.get('SCRIPT_NAME', ''))
26 offset = request_uri.startswith(script_name) and len(environ['SCRIPT_NAME']) or 0
27 environ['PATH_INFO'] = request_uri[offset:].split('?', 1)[0]
28 return self.app(environ, start_response)
29
30 # Set the application
31 application = get_wsgi_application()
32 application = PassengerPathInfoFix(application)
I hope somebody can help Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|