Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#23716 closed Uncategorized (invalid)

Reverse url doesn't container port-number

Reported by: Lars Solberg Owned by: nobody
Component: Core (URLs) Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When developing sites, you are often ending up with using something that is not port 80 or 443 to test your site.
Looks like this breaks the stuff like from django.core.urlresolvers.reverse.
Digging into the problem, I found that the problem was around https://github.com/django/django/blob/1.7/django/http/request.py#L129

The solution is fairly simple by changing the current_uri line to eg:
"""
current_uri = '%s://%s%s%s' % (self.scheme,

self.get_host(), ':%s' % (self.METASERVER_PORT? if self.METASERVER_PORT? not in ['80', '443'] else ), self.path)

"""

However, I have the feeling that this would have been fixed a long time ago, and is probably left out by design. Or?

Change History (5)

comment:1 Changed 9 years ago by Lars Solberg

Since Django might be running behind reverse proxies, and ending up having a SERVER_PORT that is not the "correct" port. Maybe this is better to have as a configurable option?

comment:2 Changed 9 years ago by Tim Graham

What about the logic in get_host(): https://github.com/django/django/blob/d92b08536d873c0966e8192e64d8e8bd9de79ebe/django/http/request.py#L65-L75

Maybe your Web server isn't setting the headers appropriately?

comment:3 Changed 9 years ago by Tim Graham

Resolution: needsinfo
Status: newclosed

comment:4 Changed 9 years ago by Lars Solberg

Sorry for the late response, but this helped me a lot to fix my issue! Thanks!

I ended up writing a mini-middleware to get this to work based on an environment-variable.
Dumped it at https://gist.github.com/xeor/2a0de36f7d686448408a if anyone is interested

comment:5 Changed 9 years ago by Tim Graham

Resolution: needsinfoinvalid
Note: See TracTickets for help on using tickets.
Back to Top