Задать вопрос

Тел: +7 965 3737 888

436

Просмотров

2

Ответов

Flash Message Template Tag

<p>Flash message add-on for Django. Uses sessions. Behavior is such that you set a flash message in a view. That message is stored in the sesssion. Then whenever it is that the message gets displayed, it is removed from the session (never to be heard from again)</p>
<p><strong>Installation:</strong></p>
<p>In your settings, enable the following items. </p>
<p>TEMPLATE_CONTEXT_PROCESSORS
django.core.context_processors.request</p>
<p>MIDDLEWARE_CLASSES
django.contrib.sessions.middleware.SessionMiddleware</p>
<p>Then put it into a file called flash.py in your templatetags directory.</p>
<p><strong>Usage:</strong></p>
<p>It's pretty simple. Do something like this in your view ..</p>
&gt;&gt;&gt;request.session['flash_msg'] = 'Your changes have been save'
&gt;&gt;&gt;request.session['flash_params'] = {'type': 'success'}

<p>And maybe put something like this in your template</p>
{% load flash %}
{% flash %}
  &lt;h2&gt;{{ params.type }}&lt;/h2&gt;
  {{ msg }}
{% endflash %}

<p>It also support a flash template, you can specify a file
FLASH_TEMPLATE in your settings file and then that file will be rendered with msg and params as available variable.
Usage for this would simply be {% flash_template %} and then you gotta make a template file that does whatever you like.</p>
<p>Outside of that just be aware you need the Django session middleware and request context installed in your app to use this.</p>

Вопрос полезен? Да0/Нет0
file_3579.py(3.4Кб)
None

Ответы (2):

Ответplucas:19.05.2008
Ответ полезен? Да0/Нет0

I had to make the following change starting at line 57, for this to work with the latest django:

if ret is not None:
        context.update(ret)
        return self.nodelist.render(context)

Ответjustinhomi:01.02.2008
Ответ полезен? Да0/Нет0

I think this code may have been responsible for user-login problems. Occasionally my application would start rejecting all users from login, and I'd have to restart the app. After removing this code from my application the problem went away. However, that wasn't the only change to my code, so I can't be sure. But it was the only change directed towards solving the login problem.