Anonymous
Anonymous

Reputation: 1

How to remove port number from url in production server in django project?

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=/

Upvotes: 0

Views: 806

Answers (3)

Seyedmahdi moosavyan
Seyedmahdi moosavyan

Reputation: 95

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

Upvotes: 2

Omer Yacine
Omer Yacine

Reputation: 61

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.

Upvotes: 1

Ruban Bob
Ruban Bob

Reputation: 77

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)

Upvotes: 0

Related Questions