10

我尝试在具有自定义设置的命令中执行 runserver。但未加载设置:

from django.core.management.base import BaseCommand
from django.core.management import call_command
from django.core.management import setup_environ, ManagementUtility

import settings_api

setup_environ(settings_api)

class Command(BaseCommand):
    help = "Local API to retrieve realtime quotes"

    def handle(self, *args, **options):
        if not settings_api.DEBUG:
            call_command('runserver',  '127.0.0.1:8002')
        else:
            call_command('runserver',  '0.0.0.0:8002')

输出是:

Used API settings
Used API settings
Validating models...

0 errors found
Django version 1.4b1, using settings 'site.settings'
Development server is running at http://0.0.0.0:8002/
Quit the server with CONTROL-C.
4

2 回答 2

19

runserver除非通过,否则强制默认设置--settings=。如果您需要自定义设置,请使用单独的 WSGI 容器(甚至是内置容器,您自己提出)。

于 2012-07-25T07:40:17.543 回答
14

Ignacios 的回答为我指明了正确的方向:使用自定义设置参数执行命令解决了它:

./manage.py command --settings=settings_api

更多细节在这里

于 2012-07-25T07:51:36.150 回答