In django, how do I call the subcommand 'syncdb' from the initialization script?

前端 未结 5 1928
故里飘歌
故里飘歌 2020-12-04 16:42

I\'m new to python and django, and when following the Django Book I learned about the command \'python manage.py syncdb\' which generated database tables for me. In developm

5条回答
  •  遥遥无期
    2020-12-04 17:07

    You could create a new script that you call instead of manage.py that calls manage.py:

    from subprocess import call
    call(["python", "manage.py", "syncdb"])
    call(["python", "manage.py", "runserver"])
    

    If you don't need to add an admin you could change the second line like this:

    call(["python", "manage.py", "syncdb", "--noinput"])
    

    I'm assuming that what you're trying to do is create your db and then start your server with one command every time.

提交回复
热议问题