I am new to Django and my project consists of two apps: a typical blog-style web site app and an API app. For the latter, I do not need the majority of middleware that is configured by default. Yet, I can't figure out what's the best approach to use the default middleware stack for the web site app, but not for the other.
If I understand correctly, the Django middleware layer does not take into account which app a view belongs to.
Approaches that come to my mind are:
1. Define only the common subset of middleware that's used by both apps in the project settings. And define a custom middleware class (e.g. WebPageMiddleware) that combines the bunch of web-site related middleware functions. Then decorate each view in the web site app with this aggregate middleware. The problem I see with this approach is that I would have to replicate the middleware stacking logic that's already handled somewhere in the Django codebase? And it just takes one time to forget adding the decorator to miss a bunch of critical protection middleware.
2. Use two Django projects, one for the web site and one for the API app. That would cleanly separate the settings but it would mean I have to take care of two deployments (probably even a good thing).
Most probably there is a simple solution, but being a Django noob I must just not be able to see it?
Thanks!
Robert