Finding the site_id of a Site in Django Admin

后端 未结 3 1441
花落未央
花落未央 2020-12-16 04:45

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 f

相关标签:
3条回答
  • 2020-12-16 05:00

    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$
    
    0 讨论(0)
  • You can find the site_id in the address bar.

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

    0 讨论(0)
  • 2020-12-16 05:27

    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.

    0 讨论(0)
提交回复
热议问题