'dev_appserver.py: Run init script from command line? (instead of interactive console)

After starting my app using dev_appserver.py --enable_console true my_app/, I go to localhost:8000, select the interactive console, and then run a Python script that initializes the datastore.

Is there a way to run this init script from the command line?

I looked at --python_startup_script my_init_script.py, but that is called before the app is started, and so it doesn't make sense.



Solution 1:[1]

Moving details from comments section to full answer

Don't know if that is possible but a possible workaround could be to put this code at the beginning of your main.py or whatever is your main file.

The process then becomes - your app starts, loads your main file (maybe when someone visits your home page) which checks if a flag is set. If flag is not set, it runs your datastore init script and sets the flag (maybe the flag is set in datastore itself).

I had something similar to what I described but the code is triggered when you try to access the home page url.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 NoCommandLine