Recommend to avoid FlatpageFallbackMiddleware unless absolutely required
In most cases you don't need conflicting routing rules in urls.py
so it's easier to just include('django.contrib.flatpages.urls')
. As a free bonus you get to avoid all kinds of problems with other middleware, contextprocessors and the CSRF framework.
I can see how the middleware is useful if for some reason you have to put the flat pages in the same URL prefix another application uses but it's a workaround that breaks the documented routing behavior. I for one don't expect apps to provide their own url routing middleware instead of urls.py
and I can't see how flatpages is an exception here.
Change History
(6)
Keywords: |
flatpages added
|
Triage Stage: |
Unreviewed → Accepted
|
Severity: |
→ Normal
|
Type: |
→ Cleanup/optimization
|
Easy pickings: |
unset
|
Has patch: |
set
|
Patch needs improvement: |
set
|
UI/UX: |
unset
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
More importantly, using the
FlatPages URLconf
isn't even mentioned as an option in the docs. However, it should be noted that theFlatPages URLConf
has to come last in your patterns, because it will match *anything* and pre-empt any patterns after it.Both use cases (middleware and
URLConf
) are valid, and I'm not convinced that preference should be given to one or the other. At the very least they should be documented equally, though.