如何在 Django 项目之外(例如在 Tornado 中)使用 manage.pysyncdb?

发布于 2024-10-07 09:32:28 字数 2011 浏览 4 评论 0原文

我正在浏览 http://lincolnloop。 com/blog/2009/sep/15/using-django-inside-tornado-web-server/ 我认为如果我们在 Tornado 中需要的话,使用 Django 的某些部分是有趣且有用的。

基于 http://lincolnloop 中的设置.com/blog/2009/sep/15/using-django-inside-tornado-web-server/ 我们如何使用 manage.pysyncdb

到目前为止,这是我尝试过的: 我尝试将manage.py转移到与tornado项目相同的文件夹,并运行manage.pysyncdb,但它返回说未找到settings.py。

比我尝试将setting.py移动到同一文件夹并再次运行manage.py。它告诉我没有找到固定装置。这一次,我不知道如何配置 settings.py,因为这不是 Django 项目。

有什么建议或想法吗?

=================更新======================

大家好, 继续上述 Agos 提供的使用建议, 我尝试运行 python manage.pysyncdb --settings=dj_tornado 并返回

`"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.)"

所以我所做的是运行 django-admin.pysyncdb --settings=dj_tornado 并返回” django.core.exceptions.ImproperlyConfigured: 你还没有设置数据库ENGINE设置。”

但奇怪的是数据库引擎已经设置好了。我该如何解决这个问题?顺便说一句,我正在使用 django 1.2.3 和 Tornado 0.2。

=================再次更新======================

大家好, 我已经应用了 Agos 提供的建议,在与 manage.py 相同的文件夹中使用了 settings.py 文件,并运行了命令 django-admin.pysyncdb --settings=dj_tornado 。 我仍然收到错误:

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

但我已经配置了基于数据库的引擎,如下所示: 在 dj_tornado.py 中:

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

        }
    }
)

我有点束手无策。如何在 Django 项目之外使用syncdb?

最好的。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁杀 2024-10-14 09:32:28

如果我正确的话,您可以使用 --settings 开关将 manage.py 指向 dj_tornado.py,这是

更新 1

之后 的设置文件帮助,可在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.

所以我会尝试这个:

python manage.py syncdb --settings=dj_tornado

更新2

另一个错误,对答案的另一个更新!
首先,考虑到该博客文章已经很旧了(2009 年 9 月)。姜戈的

DATABASES

setting has been updated since 1.2.

博客文章中的语法是:

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

对于 Django 1.2.X,这肯定是不正确的。这将是等效的版本:(

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

对于代码的可怕格式感到抱歉)。

如果这仍然不起作用,我会考虑创建一个“标准”Django 设置文件来导入。但我的赌注是数据库设置语法。

上次更新,我发誓

您是否尝试过使用新语法再次使用 django-admin.py ?如果是这样,但仍然不起作用,最小的 settings.py 就是这样:

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

您还可以将原始配置保留在 dj_tornado.py 中,并使用 settings.py 来执行syncdb。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文