Home > Back-end >  How to remove port number from url in production server in django project?
How to remove port number from url in production server in django project?

Time:08-10

I am deploying my project in production server but the port number is coming in the url. So is there any way to remove the port number from url in Django

http://domain_name:8586/admin/login?next=/

CodePudding user response:

You need to change django's default port to 80. Because all browsers(clients) will test port 80 if you don't enter any port

CodePudding user response:

If you run your app on port 80 (the default port for http) you won't need to write the port number to access it.

Any client (browser) will try port 80 if no port number was specified.

CodePudding user response:

This will help:

from urllib.parse import urlparse

in_url = "http://domain_name:8586/admin/login?next=/"

parser_url = urlparse(in_url)
out_url = parser_url._replace(netloc=parser_url.netloc.replace(str(parser_url.port), "")).geturl()
print(out_url)
  • Related