Why does django complain that I have not set my ENGINE yet?

后端 未结 1 481
失恋的感觉
失恋的感觉 2021-01-23 10:16
DATABASES = {
    \'default\': {
        \'ENGINE\': \'django.db.backends.mysql\', # Add \'postgresql_psycopg2\', \'postgresql\', \'mysql\', \'sqlite3\' or \'oracle\'.
          


        
相关标签:
1条回答
  • 2021-01-23 10:43

    I set mine the old way and the new way, so that it's not django-version-specific:

    DATABASE_ENGINE   = 'django.db.backends.sqlite3'
    DATABASE_NAME     = '/path/to/db/foo.sqlite3'
    DATABASE_USER     = ''
    DATABASE_PASSWORD = ''
    DATABASE_HOST     = ''
    DATABASE_PORT     = ''
    
    DATABASES = {
      'default': {
        'ENGINE':   DATABASE_ENGINE,
        'NAME':     DATABASE_NAME,
        'USER':     DATABASE_USER,
        'PASSWORD': DATABASE_PASSWORD,
        'HOST':     DATABASE_HOST,
        'PORT':     DATABASE_PORT,
      }
    }
    

    But yeah, I'd double check that your installation is the version you think.

    UPDATE:

    You may be trying to import something from settings in an admin module, and importing the admin module in settings. Sometimes circular-imports result in the above.

    In particular, using reverse("url-name") within settings can cause this, because it ends up forcing it to look at the "site" table at some deep-dark level...

    UPDATE2:

    Sorry, to explain the above:

    • A circular import is when a module A imports from module B, and at some level, module B also needs stuff from module A. At some point during that second level of depth, it generally fails in some inscrutable way.
    • Reverse() is the function to turn a url's name (the name="foo" in urls.py) back into the url itself. This makes calls that are not always possible in settings or admin modules.

    UPDATE3:

    Looking at the ticket djangobb.org/ticket/81 you pointed to, to break some of the terms down, the csrf token is a template tag used to add Cross Site Request Forgery protection:

    http://docs.djangoproject.com/en/dev/ref/contrib/csrf/

    It generally looks like this, to grep from a project of mine:

    # grep -ri csrf .
      ./registration/login.html:  <form method="post" action="{% url django.contrib.auth.views.login %}">{% csrf_token %}
    

    The bit about the trunk of djapian, though I don't know what djapian is myself, generally means a direct install of the (typically svn) trunk -- or "most up to date, checked in version, which is newer than any release, and possibly tested, official version". Typically, this involves doing something like an svn checkout http://wherever.com/someproject/trunk/ ./someproject and then going to that directory to install.

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