Django MongoDB Engine error when running tellsiteid

后端 未结 9 866
野的像风
野的像风 2021-02-02 04:24

SO I created a django project and app as per the tutorial and I have all the dependencies necessarry for MongoDB Engine it all seemed to be working fine and dandy till I tried e

相关标签:
9条回答
  • 2021-02-02 04:33

    For some reason none of the solutions here worked for me. python ./manage.py tellsiteid, there was no django_site collection, and commenting out 'django.contrib.sites' caused weird errors.

    Grabbing the ID from the shell worked for me though, detailed here:

    https://gist.github.com/ielshareef/2986459 or here Site matching query does not exist

    python ./manage.py shell
    >>> from django.contrib.sites.models import Site
    >>> Site().save()
    >>> Site.objects.all()[0].id
    u'4fe7aa759e654e2662000000'
    

    Put it in settings.py and everything worked great!

    0 讨论(0)
  • 2021-02-02 04:34

    If you do not need the sites functionality (which is very probable) simply turn off django.contrib.sites app and it will fix MongoDB issues related to the SITE_ID:

    INSTALLED_APPS = (   
        (...)
        # 'django.contrib.sites',  # Comment this out
        (...)
    )
    
    0 讨论(0)
  • 2021-02-02 04:35

    You haven't created any Site yet. Run manage.py syncdb to create one.

    0 讨论(0)
  • 2021-02-02 04:39

    I ran into this during my setup the other day.

    Basically you need to logo into a mongo shell and lookup your siteid then add it your settings.py

    log into a mongo shell

    mongo
    

    select your db

    use *name*
    

    then do a find() on django_site

    db.django_site.find()
    

    Then open your settings.py and edit the site_ID ="" line (mine is below)

    SITE_ID = u'4f1f82011d41c81e5c00001d'
    

    That should get you up and running

    0 讨论(0)
  • 2021-02-02 04:42

    have you tried this: http://django-mongodb.org/troubleshooting.html#site-id-issues

    0 讨论(0)
  • 2021-02-02 04:43

    Most likely you havent created a site yet, to do so you need to run the command

    python manage.py syncdb
    

    This creates the site, now you need to add its site_id in your settings file. Go get the site id, connect to mongodb engine that is running, and run the following commands

    use mydatabase --/# or whatever name you have for your database.
    db.django_site.find()
    

    you will get something like

    ObjectId("4f4e968adea3b3b30c00001d")
    

    then in your settings file, put

    site_id = u'4f4e968adea3b3b30c00001d'
    

    and the admin interface should work. Does it?

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