When I am using reverse() to redirect to a different view with some optional kwargs, as a response from the view I want to display an alert message on load of a template if a key is passed in context dictionary based on that kwarg arg which came in. This is happening fine. But as the url contains the optional path parameter any call to same view with filters is displaying the alert again and again.I want to remove that optional path parameter on display of that alert.
This is my view to calling reverse -
return HttpResponseRedirect(reverse('data_asset_formats_msg', kwargs={'msg':"Unauthorized to delete DAF-%s"%data_asset_format.data_asset_format_id}))
This is my urls -
url(r'^data_asset_format/(?P<msg>.*)/', views.data_asset_formats, name='data_asset_formats_msg'),
This is the implementation of the view data_asset_formats -
def data_asset_formats(request, **kwargs):
logr.info(kwargs)
msg = kwargs.get('msg', '')
logr.info(msg)
data_asset_format_list = EdfDataAssetFormat.objects.order_by('data_asset_format_name')
field_filter = DataAssetFormatFilter(request.GET, queryset=data_asset_format_list)
context = {'data_asset_format_list': data_asset_format_list, 'filter': field_filter, 'msg':msg}
return render(request, 'edf/data_asset_formats.html', context)
In the template - edf/data_asset_formats.html
<script>
{% if msg %}
var msg = '{{msg}}';
alert(msg);
{% endif %}
</script>
As the url path param contains the optional argument whenever the filters are filtering on this form , the param is passed along and the alter is shown on any search.
I want the template to not display the alert again and again on every filter search.