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.
I could not understand in which template I have to include
{{messages}}
in. In update form, edit form or home page form?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.
Enable the middleware module by adding
'django.contrib.sessions.middleware.SessionMiddleware'
toMIDDLEWARE_CLASSES
in settings.py.In your view, use something like
messages.add_message(request, messages.INFO, 'Stuff happened')
to record information where it makes sense.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.
精彩评论