Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using phased with contrib.messages #12

Open
clime opened this issue Mar 2, 2014 · 1 comment
Open

using phased with contrib.messages #12

clime opened this issue Mar 2, 2014 · 1 comment

Comments

@clime
Copy link

clime commented Mar 2, 2014

I am trying to apply phased on a snippet where I render flash messages but It doesn't quite work. I get the messages printed on all the pages several times. It's like they are staying in session as not-yet-printed even though they have been already printed by second_pass_renderer.

@clime
Copy link
Author

clime commented Mar 2, 2014

The problem was again in the order of middleware classes. To solve this particular problem PhasedRenderMiddleware needs to be below MessageMiddleware. Here is my current order:

MIDDLEWARE_CLASSES = (
    #'django.middleware.cache.UpdateCacheMiddleware',
    'phased.middleware.PatchedVaryUpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'middleware.HttpAuthMiddleware',
    'middleware.ProfilerMiddleware',
    'middleware.AnonymousUserMiddleware',
    'middleware.UserMemberMiddleware',
    'middleware.VaryOnAcceptMiddleware',
    'watson.middleware.SearchContextMiddleware',
    #'debug_toolbar.middleware.DebugToolbarMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
    'phased.middleware.PhasedRenderMiddleware',
)

That is FetchFromCacheMiddleware and PhasedRenderMiddleware are on the last places. I hope it won't cause problems somewhere else because in docs PhasedRenderMiddleware is on the first place.

philipn added a commit to philipn/django-phased that referenced this issue Aug 25, 2014
Because of codysoyland#12, I had
to move PhasedRenderMiddleware to the bottom(ish) of my
`MIDDLEWARE_CLASSES`. This fixed the issue with the `MessageMiddleware`,
but caused new issues with other middleware I had that altered the
length of the response.

Ideally, these other middleware classes would check to see if
`Content-Length` was set, and if so, re-adjust the content length
header. Unfortunately, this doesn't seem to be the case, and it seems
smart for us to check to see if the header's set before adding it in
here, anyway.
philipn added a commit to philipn/django-phased that referenced this issue Aug 25, 2014
Because of codysoyland#12, I had
to move PhasedRenderMiddleware to the bottom(ish) of my
`MIDDLEWARE_CLASSES`. This fixed the issue with the `MessageMiddleware`,
but caused new issues with other middleware I had that altered the
length of the response.

Ideally, these other middleware classes would check to see if
`Content-Length` was set, and if so, re-adjust the content length
header. Unfortunately, this doesn't seem to be the case, and it seems
smart for us to check to see if the header's set before adding it in
here, anyway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant