开发者

Whats the best way to display message after CRUD operation In Django

I have been doing CRUD operation in Django but I am having problem with what to do after successful operation.

Is there any way that i can redirect the user to Home page with small message on top of page like

"Record Successfully added or something else" like Google does with Dismiss hyperlink :)

EDIT:

Actually t开发者_JS百科hat a is full documentation and not a simple example.

  1. I could not understand in which template I have to include {{messages}} in. In update form, edit form or home page form?

  2. I don't understand where I need to define messages. I use only generic views so I am confused.


Use the django.contrib.messages framework to get the same messaging style as used in Django admin.

  1. Enable the middleware module by adding 'django.contrib.sessions.middleware.SessionMiddleware' to MIDDLEWARE_CLASSES in settings.py.

  2. In your view, use something like messages.add_message(request, messages.INFO, 'Stuff happened') to record information where it makes sense.

  3. In your template, you'll have a list messages which you can iterate over where it makes sense in your design - the example in the documentation shows a full example which exposes the tags as CSS classes for ease of styling.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜