Home > Software engineering >  dev_appserver.py: Run init script from command line? (instead of interactive console)
dev_appserver.py: Run init script from command line? (instead of interactive console)

Time:03-12

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.

CodePudding user response:

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.

  • Related