使用自定义设置的命令中的Django Runserver [英] Django runserver in command with custom settings

查看:54
本文介绍了使用自定义设置的命令中的Django Runserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to execute the runserver inside a command with custom settings. 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')

输出为:

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 强制默认设置,除非通过-settings = .如果需要自定义设置,请使用单独的WSGI容器(甚至是内置的WSGI容器).

runserver forces default settings unless passed --settings=. Use a separate WSGI container (or even the built-in one, brought up yourself) if you want custom settings.

这篇关于使用自定义设置的命令中的Django Runserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆