Refactor template engine as library

This pull request fixes Trac ticket #17093.
Was it previously possible to use a loader class that was duck-typed (met all the API constraints) but didn't actually inherit from the base loader? If so, any such loader classes (and quite likely there aren't any in the wild) would break with `AttributeError` on this line.

You could replace this with an `issubclass(django.template.loaders.base.Loader)` check. That would allow duck-typed old-style Loaders to keep working, at the expense of making duck-typed new-style loaders completely impossible. On the whole that's probably a bad tradeoff.

I think what you've done here makes sense, just making note of the consequences.

This check can be removed in a couple versions anyway.