英文:
How to find which site ids I have in Django Admin panel sites
问题
我已删除我的先前网站 xxx.xxx.com,并添加了一个新网站 xx1.xxx.com。然后在 settings.py 中,我将站点 ID 配置为 2,但仍然出现了 django.contrib.sites.models.Site.DoesNotExist: Site matching query does not exist. 错误。我该如何使用 shell 检查我当前拥有的确切站点 ID?因为我的管理面板也无法加载。
我对 Django 还相当新,所以如果这是一个非常基本的问题,我很抱歉。
我尝试将站点 ID 从 1 更改为 2。
英文:
I have deleted my previous site xxx.xxx.com and added a new site xx1.xxx.com. So then in the settings.py I have configured the site id to 2 and, yet it's not giving me the django.contrib.sites.models.Site.DoesNotExist: Site matching query does not exist. error. How can I check the exact site ids I have right now with the shell. Because my admin panel is not loading too.
I am pretty new to django. So apologies if this is a very basic one to ask.
I tried to change the site id from 1 to 2
答案1
得分: 0
你可以使用以下代码检索你的站点:
from django.contrib.sites.models import Site
sites = Site.objects.all()
for site in sites:
print(site.id)
同时确保你已正确更新了你的 settings.py 文件中的 SITE_ID 设置,以匹配新站点的 ID。
英文:
You can retrieve your sites with the import
from django.contrib.sites.models import Site
sites = Site.objects.all()
for site in sites:
print(site.id)
And ensure that you have correctly updated the SITE_ID setting in your settings.py file to match the ID of the new site.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论