Python Django - 站点匹配查询不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16068518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Django - Site matching query does not exist
提问by felix001
Im trying to get the admin site of my app in Django working. Ive just sync`d the DB and then gone to the site but I get the error ...
我试图在 Django 中获取我的应用程序的管理站点。我刚刚同步了数据库,然后去了网站,但我收到了错误......
Site matching query does not exist.
Any ideas ?
有任何想法吗 ?
采纳答案by karthikr
Every django app needs a Siteto run. Here you do not seem to have it.
每个 django 应用程序都需要Site运行。在这里你似乎没有它。
Log into your django shell
登录到你的 django shell
$> ./manage.py shell
>>> from django.contrib.sites.models import Site
>>> site = Site()
>>> site.domain = 'example.com'
>>> site.name = 'example.com'
>>> site.save()
or
或者
$> ./manage.py shell
>>> from django.contrib.sites.models import Site
>>> site = Site.objects.create(domain='example.com', name='example.com')
>>> site.save()
You should be all set.
你应该准备好了。
回答by Evangelos Tolias
You also need to make sure that the site domain is the same with the one you actually use. For example if you are you are accessing the admin site from http://127.0.0.1:8000/admin/then your site.domain should be: site.domain = '127.0.0.1:8000'.
您还需要确保站点域与您实际使用的域相同。例如,如果您从http://127.0.0.1:8000/admin/访问管理站点,那么您的 site.domain 应该是:site.domain = '127.0.0.1:8000'。
回答by Mr Singh
Add django.contrib.sitesin django INSTALLED_APPSand
also add SITE_ID=1in your django setting file.
添加django.contrib.sitesdjangoINSTALLED_APPS并添加SITE_ID=1您的 django 设置文件。

