简体   繁体   中英

Finding the site_id of a Site in Django Admin

I'm installing Django AllAuth into my project and have come across the following line in the documentation for that app (see docs here) :

Add a Site for your domain, matching settings.SITE_ID (django.contrib.sites app).

My settings.SITE_ID is 1, unsurprisingly. How do I 'match' this in the Django Admin? I only have 2 fields - Domain Name and Display name.

Conversely, if I create a site in the admin, how do I know what the site_id for it is?

You can find the site_id in the address bar.

显示 Django 管理和感兴趣的 url 的 Web 浏览器屏幕截图

So the line in settings.py would be: SITE_ID = 3

Go the your project path where you have manage.py file and follow the following steps:

Run teh following command in your terminal

    python manage.py shell

Then in the python shell type:

    from django.contrib.sites.models import Site

    new_site = Site.objects.create(domain='....', name='....')

    print new_site.id

This printed value will be the site_id for site matching query If you are still struck, reply. I will guide you to very simple and easy steps to enjoy the beauty of django allauth.

This works for me:

user$ python manage.py shell --settings your-settings.py

[ ... banner ... ]
>>>
>>> from django.contrib.sites.models import Site
>>>
>>> sorted([(site.id,site.name) for site in Site.objects.all()])
[(1, u'www.lvh.me'), (2, u'example.com'), (3, u'www.example.com'),...]
>>>
>>> quit()
user$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM