How to reload modules in django shell?

后端 未结 11 1189
面向向阳花
面向向阳花 2020-12-22 18:38

I am working with Django and use Django shell all the time. The annoying part is that while the Django server reloads on code changes, the shell does not, so every time I ma

11条回答
  •  情歌与酒
    2020-12-22 19:18

    Not exactly what you want, but I now tend to build myself management commands for testing and fiddling with things.

    In the command you can set up a bunch of locals the way you want and afterwards drop into an interactive shell.

    import code
    
    class Command(BaseCommand):
      def handle(self, *args, **kwargs):
         foo = 'bar'
         code.interact(local=locals())
    

    No reload, but an easy and less annoying way to interactively test django functionality.

提交回复
热议问题