[Django]-Django-extensions: Run a script using runscript which is inside a folder within scripts

8👍

You need to run the script as follows:

/manage.py runscript scripts.syllabus.first --script-args=excel.xlsx

Here scripts and syllabus are two directories containing __init__.py.

2👍

I dont have any experience with django. But the problem can be solved by adding syllabus to module lookup path. To do that add the following code in the __init__.py file under scripts directory.

import sys
import os

curr_path = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, curr_path + '/syllabus')

Or another way is to tell python that syllabus is a module itself. In that case you just need to rename first.py to __init__.py. You will then have to invoke it as

./manage.py runscript syllabus --script-args=excel.xlsx
👤Vishal

Leave a comment