* status: assigned => new
* owner: laurentluce =>
* ui_ux: => 0
* easy: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/10944#comment:14>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by oinopion):
site_url tag is a bit useless, as it take path as string. IMHO it should
work like the url tag taking names and parameters.
--
Ticket URL: <https://code.djangoproject.com/ticket/10944#comment:15>
* owner: => krzysiumed
* cc: krzysiumed@… (added)
Comment:
I added my draft where `site_url` is similar to `url` tag (actually it
calls the `url` tag function and create instance of `URLNode` to avoid
redundancy). It includes tests and docs but my english is poor. An example
of using my `site_url`:
{{{
{% site_url site 'myapp.views.viewname' %} ==>
'http://example.com/path/to/view'
{% site_url site using https 'myapp.views.viewname' %} ==>
'https://example.com/path/to/view'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/10944#comment:16>
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/10944#comment:17>
* needs_better_patch: 0 => 1
Comment:
Patch no longer applies cleanly.
--
Ticket URL: <https://code.djangoproject.com/ticket/10944#comment:18>
Comment (by mbertheau):
Replying to [comment:9 SmileyChris]:
> What's actually the good in the `{% site_url %}` tag? It seems like it
should be able to take other sites, too (if you only have one site, why
bother using this over the standard `request.build_absolute_uri()`?)
I often find myself in a situation where I need an absolute URL but cannot
use `request.build_absolute_uri()` because I don't have a request: cron
jobs, celery tasks or api modules that I don't want to couple to the
request. Afaics Django currently doesn't have a place to generate absolute
URLs without a request, so everyone is hacking their own way. `Site` is a
possible place to do it, but it'd have to learn about the scheme and port
to be complete. `RequestSite` could take these from new settings, maybe:
`SITE_SCHEME`, `SITE_PORT`.
--
Ticket URL: <https://code.djangoproject.com/ticket/10944#comment:19>
* cc: André Cruz (added)
Comment:
Seems like this would be a pretty useful feature to have, and one that I
need.
Is any one of those "hacks" blessed by the Django community? I'm doing
this:
{{{
def handcraft_absolute_url(path):
domain = Site.objects.get_current().domain
scheme = 'https' if SESSION_COOKIE_SECURE else 'http'
return '{scheme}://{domain}{path}'.format(domain=domain, path=path,
scheme=scheme)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/10944#comment:20>