0

I am writing some python scripts for my Django project. And I am running it using manage.py and shell.

import json is not working if I am running it with manage.py and sell.

But it is working if I try without shell and manage.py I don't know why this is happening.

With manage.py and shell: (Not working)

python3 manage.py shell < custom_scripts/imports.py
Error: NameError: name 'json' is not defined

Without manage.py and shell: (Works)

python3 custom_scripts/imports.py

Code inside the script:

    import json
    
    print(json.loads("{}"))

Any thoughts?

Hardik Raval
  • 3,406
  • 1
  • 26
  • 28

1 Answers1

0

It wouldn't be the recommended way to do such a thing from the shell, if this is something that will be run multiple times you can create custom commands to run this for you.

Please see the answer by @danodonovan for a similar issue.