Why do you check twice for `if fname == 'course.xml'`? Seems like you're just trying to find the `course.xml` file in the package -- a more elegant and readable way to do it would be to write a generator that yields filenames and filepaths in the course directory, and then have a function that simply iterates through the generator and returns the first file named `course.xml` that it comes across -- or if it returns None, then return a `JsonResponse` with status code 400 and an appropriate error message. I'd be happy to help you write that generator, if you'd like.