I wrote many scripts to help me manage my django projects. One of them, cr_app.py
creates a new app:
#!/usr/bin/env python3
from subprocess import run
def main():
create_app()
def create_app():
name = input("The name of the app?\n")
run(f"""python3 manage.py startapp {name}""", shell=True)
if __name__ == "__main__":
main()
When I am inside of my virtual envirnment's project directory, having activated it with . bin/activate
, and, following the tutorial, I run manually
python3 manage.py startapp polls
then I find models.py
already created inside of
polls/
. But this does not happen, models.py
does not get created, when I run cr_app.py
and create a new app polls
even though I run this script
while being in the projects activated virtual environment (although cr_app.py
is not, it is located in a different, remote directory). The directory app, polls/
gets created but without models.py
inside of it. Activating the environment from within the script with run(f""". bin/activate && python3 manage.py startapp {name}""", shell=True)
fixes the issue, and models.py
gets created. Why do I have to activate my virtual environment for the second time - i.e. from within a script, after having it already activated?