开发者

how to use manage.py syncdb outside of Django project, such as in Tornado?

I was looking through http://lincolnloop.com/blog/2009/sep/15/using-django-inside-tornado-web-server/ and I thought it was interesting and useful to use parts of Django if we need it in Tornado.

Based on the setup in http://lincolnloop.com/blog/2009/sep/15/using-django-inside-tornado-web-server/ how can we use manage.py syncdb ?

Here's what i have tried so far: I've tried shifting manage.py to the same folder as the tornado project, and ran manage.py syncdb but it returns saying that settings.py is not found.

than i tried to move setting.py to the same folder and ran manage.py again. It tells me that no fixtures found. This time round, I have no idea how to configure settings.py since this is not a Django project.

Any advice or thoughts?

=================updates======================

Hi all, continuing from the above an using advice provided by Agos, i've tried running python manage.py syncdb --settings=dj_tornado and it returns

`"Error: Can't find the file 'settings.py'` in the directory containing 'manage.py'`. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an ImportError somehow.)"

So what i did is to run django-admin.py syncdb --settings=dj_tornado and it returns "django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet."

But the weird thing is that the database engine has been set. How would I go about fixing this? i'm using django 1.2.3 and Tornado 0.2 by the开发者_StackOverflow way.

=================updates again======================

Hi all, i've applied the advice provided by Agos, with a settings.py file in teh same folder as manage.py, and ran the command django-admin.py syncdb --settings=dj_tornado. I still received the error:

django.core.exceptions.ImproperlyConfigured: You haven't set the database ENGINE setting yet.

But i have already configured the database based engine as follows: in dj_tornado.py:

from django.conf import settings
settings.configure(
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3', 
            'NAME': 'dev.db',

        }
    }
)

I'm kind of at my wits end. How do i use syncdb outside of Django project?

Best.


If I got it correctly, you can just use the --settings switch to point manage.py to the dj_tornado.py, which is your settings file after all

Update 1

from the help, available at python manage.py help:

Options:
  --settings=SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.

So I would try this:

python manage.py syncdb --settings=dj_tornado

Update 2

Another error, another update to the answer!
First of all, consider that that blog post is quite old (september 2009). Django's

DATABASES
setting has been updated since 1.2.

The syntax in the blog post was:

settings.configure(DATABASE_ENGINE='sqlite3', DATABASE_NAME='dev.db')

With Django 1.2.X this is surely not correct. This would be the equivalent version:

settings.configure(DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'dev.db'
    }
})

(sorry for the horrible formatting of the code).

If this still won't work, I'd consider creating a “standard” Django settings file to import. But my bet is on the db settings syntax.

Last update, I swear

Have you tried using django-admin.py again with the new syntax? If so, and still didn't work, a minimal settings.py would be just this:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'dev.db'
    }
}

You can also keep the original configuration inside dj_tornado.py and use settings.py just to do syncdb.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜