Browser client side django playground using pyscript

Playground: Django Playground

Code: Django Playground

What is it?

Django Playground runs your python code client side directly in your browser using pyscript. There is no server.

When this website is launched in your browser, it runs some initialization code in your browser to:

  • Create a model

    class Dog(models.Model): 
        name = models.TextField()
  • Configure django to work with an in memory sqlite database in your browser

  • Migrate with syncdb to create the table in the sqlite database

Why did I do it?

Because we can. I saw it at pycon and I wanted to code something with new tech today.

What can it be used for?

One use could be to make supplemental interactive documentation, such as working orm examples from the docs.

Where’s the django code?

It starts here. The code generally follows what’s required to run a single file django project. It becomes more challenging when I need to make a model. The model must be associated with an app. The “project” then expects the app follows a certain structure, ie a package with a I couldn’t grok how to get this “structure” inside pyscript. Instead, I have a single file with my AppConfig overwritten with enough to make it work.

1 Like