1. Why an error message?
I wrote a simple hello world script which was named:
mytest01.py
, and placed it on:
/mysite/scripts/
. I ran it by:
python manage.py runscript mytest01
The code displayed "Hello world!" as I expected, but an error message was displayed on the next lines:
No (valid) module for script 'mytest01' found
Try running with a higher verbosity level like: -v2 or -v3
CommandError: An error has occurred running scripts. See errors above.
Why did it happen?
2. Solution
Good job testing your script — you're very close! The issue here is about how Django Extensions finds scripts.
Here’s what’s happening:
✅ What you did:
-
You wrote a file:
/mysite/scripts/mytest01.py -
You ran:
-
The script ran and printed
"Hello world!", but also showed an error.
❌ Error:
This means Django Extensions found the file, tried to run it, and partly succeeded, but it
didn’t find a valid run() function in it — which is required for runscript.
✅ How to fix it:
Make sure your script mytest01.py looks like this:
🔧 Important:
runscriptexpects a function namedrun()in your script. If you don't have it, it raises that error — even if some code gets executed.
✅ Also: File location
Make sure the file is in a folder listed under your SCRIPTS_DIRS setting.
For example, in your Django project’s settings.py, you can add:
Or place it in the default:
<your_app>/scripts/ (e.g., cats/scripts/)
✅ Summary checklist:
-
✅ File is named
mytest01.py -
✅ Script is inside a
scripts/folder recognized by Django Extensions -
✅ Script has a function called
run()
Let me know if you'd like help writing or testing another script!
