0
votes

I'm getting this error in the below function in my views.py file. I don't know what 'WSGIRequest' is or why it's throwing an error.

Here the settings.MEDIA_ROOT means it will list all the files in that directory

def run_existing_query(request):
 context = {}
 print(settings.MEDIA_ROOT)
 context["download"] = ""
 context["list_of_queries"] = os.listdir(settings.MEDIA_ROOT)

 if request.method == "POST": 
    MODULE_DIR = 'settings.MEDIA_ROOT'
    py_file = glob.glob(os.path.join(MODULE_DIR, 
    request['selected_query']+'.py'))
    module_name = pathlib.Path(py_file).stem
    module = importlib.import_module(module_name)
    qe = module.QueryExecutor()  #Query executor is Class name 
    context["download"] = "Hello"
return render(request, "run_existing.html", context)

Why am I getting this error?

1

1 Answers

0
votes

You haven't told us where the error occurs in your code, but I highly suspect it's in request['selected_query'].

You are subscripting the request object. But it doesn't seem to have a __getitem__ method (see source). That's why the error is raised.

Maybe you intend to address request.GET['selected_query'] or .POST['selected_query']?