How to change name, domain of site in Django
I am able to change the name of the domain and site in the administration panel (http://127.0.0.1:8000/admin). However, when I try to make changes directly to the database in the table django_site
, it is not reflected in the administration panel (nor is it reflected开发者_运维技巧 in the URL of links sent in activation emails).
Why is this change not working directly in the database, and how can I change the site/domain other than in the administration panel?
As per the docs, Django caches the site upon the first request. Therefore you need to call Site.objects.clear_cache()
:
As the current site is stored in the database, each call to Site.objects.get_current() could result in a database query. But Django is a little cleverer than that: on the first request, the current site is cached, and any subsequent call returns the cached data instead of hitting the database.
If for any reason you want to force a database query, you can tell Django to clear the cache using Site.objects.clear_cache()
精彩评论