Django: absolute URI in batch/cron job

194 Views Asked by At

How can you get the absolute uri (with domain and scheme (http/https)) from a batch/cron job?

The method build_absolute_uri() needs an HttpRequest, which I don't have in a cron job.

1

There are 1 best solutions below

0
On

Two examples:

from django.contrib.sites.models import Site

url = 'http://' + Site.objects.get_current().domain + my_obj.get_absolute_url()

or

from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse

url = 'http://' + Site.objects.get_current().domain + reverse('my_view')