Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 13
    This is really handy when you don't have access to HttpRequest object. e.g. in tasks, signals etc. Commented Nov 11, 2014 at 10:04
  • 7
    before using this you should enable sites framework docs.djangoproject.com/en/dev/ref/contrib/sites/… Commented Jul 1, 2015 at 15:12
  • To change example.com to something also: Site.objects.all()[0] returns 'example.com' and has id=1, which specified in settings.py. Just do Site.objects.create(name='production', domain='prodsite.com') and set SITE_ID=2 in settings.py. Now Site.objects.get_current().domain returns 'prodsite.com'. Commented Nov 7, 2019 at 14:10
  • 1
    My development domain is at "127.0.0.1:8000" and the production domain is 'paidfor.pythonanywhere.com'. I want my Django to find own its own which domain is it running on. Commented Jun 7, 2021 at 7:51
  • 1
    @ShalomAlexander How is this not flexible between dev and prod? get_current() takes care of that abstraction for you. Commented Jan 17, 2023 at 1:07