Fixed #21530 -- Prevent AttributeError in default URLconf detection code.

Thanks to @dmyerscoug for the report and original patch
and to @alasdairnicol for the added tests.