Changes between Version 9 and Version 10 of ReplacingGetAbsoluteUrl


Ignore:
Timestamp:
Nov 7, 2008, 9:37:56 AM (16 years ago)
Author:
Archatas
Comment:

The most reasonable place to take the domain name from is the current site from the Site model. PROTOCOL and PORT might be in the settings.

Legend:

Unmodified
Added
Removed
Modified
  • ReplacingGetAbsoluteUrl

    v9 v10  
    9898{{{
    9999#!python
     100from django.contrib.sites.models import Site
    100101from django.conf import settings
    101102import urlparse
     
    110111        except NotImplemented:
    111112            raise
    112         # Should we look up a related site?
    113         #if getattr(self._meta, 'url_by_site'):
    114         prefix = getattr(settings, 'DEFAULT_URL_PREFIX', 'http://localhost')
    115         return prefix + path
     113        protocol = getattr(settings, "PROTOCOL", "http")
     114        domain = Site.objects.get_current().domain
     115        port = getattr(settings, "PORT", "")
     116        if port:
     117            assert port.startswith(":"), "The PORT setting must have a preceeding ':'."
     118        return "%s://%s%s%s" % (protocol, domain, port, path)
    116119    get_url.dont_recurse = True
    117120   
Back to Top