简体   繁体   English

Django runserver in command with custom settings

[英]Django runserver in command with custom settings

I try to execute the runserver inside a command with custom settings. 我尝试使用自定义设置在命令中执行runserver。 But the settings are not loaded: 但是没有加载设置:

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')

Output is: 输出是:

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.

runserver forces default settings unless passed --settings= . runserver强制默认设置,除非传递--settings= Use a separate WSGI container (or even the built-in one, brought up yourself) if you want custom settings. 如果您想要自定义设置,请使用单独的WSGI容器(甚至是内置的容器)。

Ignacios answer pointed me the right direction: executing the command with custom settings param solved it: Ignacios的回答指出了正确的方向:用自定义设置执行命令param解决了它:

./manage.py command --settings=settings_api

More details here 更多细节在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM