Show Success or Failure message in Python Django

# Save Flash Message Data
messages.success(request, 'Settings Updated successfully.')
# Show Message in Html from Message variable
{% if messages %}

    {% for message in messages %}

        <div class="alert alert-success">

             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>

             <strong>Success!</strong> {{message}}


    {% endfor %}

{% endif %}
Or Like this,
<div class="col-sm-6">

    {% if messages %}

        <ul class="messages">

            {% for message in messages %}

                <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>

            {% endfor %}


    {% endif %}


Explode, Implode, Rtrim in Python Django

Explode, Implode, Rtrim in Python Django like php
# Explode in python:
temp = temp1.split(",")
# Implode in python:
temp2 = ','.join([str(i) for i in temp])
# rtrim() in python:
temp = name.rstrip(',')
# Implode Array in python:
temp_Arr = ['FurnitureMakeover', 'nurserydresser', 'funcycled', 'dresser']

temp_Tags = ','.join(temp_Arr)

To strip/remove HTML tags from an existing string we can use the strip_tags function.

To strip/remove HTML tags from an existing string we can use the strip_tags function:
# import the strip_tags
from django.utils.html import strip_tags
# simple string with html inside.
html = '<p>paragraph</p>'

print html # will produce: <p>paragraph</p>

stripped = strip_tags(html)

print stripped # will produce: paragraph
# This is also available as a template tag:
{{ somevalue|striptags }}
# If you want to remove only specific tags you need to use the removetags
from django.template.defaultfilters import removetags
html = '<strong>Bold...</strong><p>paragraph....</p>'

stripped = removetags(html, 'strong') # removes the strong only.

stripped2 = removetags(html, 'strong p') # removes the strong AND p tags.
# Also available in template:
{{ value|removetags:"a span"|safe }}

How to Add a Custom Function in Jquery Form Validator

How to Add a Custom Function in Jquery Form Validator?


First, write the custom function like below.

jQuery.validator.addMethod("mobile_prefix", function(value, element) 

        var select=true;

        var mobile_prefix=$("#mobile_prefix").val();

        if(value && !mobile_prefix)

        return select;



Secondly, In the form validator function call the above custom defined function. It will return TRUE / FALSE.



                noSpace: true
            "confpassword": {

          messages: {
            "confpassword": {
                required:"Enter confirm password",
                equalTo: "Password mismatch",
                required:"Enter password",
                noSpace : "no space please."
            "mobile_number": {
                required: "Enter Mobile Number",
                minlength: "Mobile number atleast 10",
               mobile_prefix:"Please select code"

If you like the post, please comment below & follow us on social platform.