Comments on this assumption about running on a dev server against a real instance in the application engine (python)?

I am in the application engine project where I would like to add a link to the Javascript test runner, which I would like to use only when starting the development server. I conducted several experiments in the local shell with the configuration loaded using the method found in NoseGAE and in real time on the "App Engine Console" [1], and it looks to me like a separate battle of a real instance, and the dev server is the presence module google.appengine.tools. Which led me to this utility function:

def is_dev():
    """
    Tells us if we're running under the development server or not.
    :return:
    ``True`` if the code is running under the development server.
    """
    try:
        from google.appengine import tools
        return True
    except ImportError:
        return False

The question (finally!) Will be: is this a bad idea? And in that case, can anyone suggest a better approach?

[1] http://con.appspot.com/console/ ( )

+3
3

:

DEBUG = os.environ['SERVER_SOFTWARE'].startswith("Dev")

- - - , .

+6

:

import os
def onDevServer():
    return os.environ['SERVER_SOFTWARE'].find('Development') >= 0

, , true, . , , , .

+1

I am not a Google application developer, but I would not have made this 100% dynamic, but also looked at the value from the configuration file. I am sure that you will encounter a problem that you want to see this console in the prod (google servers) system or run the local version without dev code (for testing).

To summarize: this logic is great for small things like adding a debug link, but provides a way to overwrite it (e.g. with a configuration value)

0
source

Source: https://habr.com/ru/post/1749798/


All Articles