NameError name slugify is not defined Django error

Most of the case When you tried to add a slug keyword for page model you will get error NameError: name ‘slugify’ is not defined Django error.Here we are discussing how to solve “NameError: name ‘slugify’ is not defined Django error”

Here is the model

from django.db import models

# Create your models here.
class page(models.Model):
 """Model representing a book (but not a specific copy of a book)."""
 
 page_id = models.AutoField(primary_key=True)
 
 page_title = models.CharField(max_length=200)

 author_name = models.CharField(max_length=100)
 
 page_content = models.TextField(max_length=1000, help_text='Enter your page content')
 
 page_name = models.SlugField(editable=False) # hide from admin

 def save(self):
 if not self.page_id:
 self.page_name = slugify(self.page_title)

 super(page, self).save()

Here is the error

“NameError: name ‘slugify’ is not defined Django error”

 

NameError name slugify is not defined Django error

How to Solve it

Step install  python-slugify module

# pip install python-slugify

Include slugify module in your model
 from slugify import slugify

NameError name slugify is not defined Django error 2

 

Multiselect dropdown with checkboxes demo code in php

Being a developer you may face a situation, have to give multiple select option for the front end user, now it is easy with the help of bootstrap multiselect script we can accomplish that task within 10 minutes. Here am going to explain you Multi select drop down with check boxes demo code in php

here is the Multiselect dropdown with checkboxes demo code in php

Step 1

Files To Include

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/css/bootstrap-multiselect.css">
</script>

Step 2

HTML Form

<div class="container-fluid"style="text-align: center;margin-bottom:200px;">
<h1>Demo Multiselect Box In PHP</h1>
<div class="row">
<div class="col-md-12" >

<form id="myForm" method="POST">
<input name="current_select_values" type="hidden" value="" id="current_select_values">
<div class="col-md-12" >
 <select size="5" name="current_select[]" multiple="multiple" id="current_select">
 <option value="current1">current1</option>
 <option value="current2">current2</option>
 <option value="current3">current3</option>
 <option value="current4">current4</option>
 <option value="current5">current5</option>
 </select>
 </div><div class="col-md-12" style="margin-top:20px;" >
 <input type="submit" value="Submit" ></div>
</form></div></div></div>

Step 3

Script Files

<script>
$(document).ready(function() {       
	$('#current_select').multiselect({		
		nonSelectedText: 'Select Current'				
	});
});

$(function () {

 
 $('#current_select').multiselect({ 
 buttonText: function(options, select) {
 var labels = [];
 console.log(options);
 options.each(function() {
 labels.push($(this).val());
 });
 $("#current_select_values").val(labels.join(',') + '');
 return labels.join(', ') + '';
 //}
 }
 
 });
});
</script>

Step 4

Post Action


<?php print_r ($_POST['current_select']); ?>

See Demo Code

Multiselect dropdown with checkboxes demo code in php

assertion error python

Assertions is one of the most advanced Exception Handling technique used in python by using the Assert statement,we can create debug message,if anything logically end up with an error.If anything fails logically AssertionError will display and end the process. here we will check assertion error python
When we are working with automatic car project their is a situation of fuel tank is empty that time we have to stop all process and stop the vehicle with an error message “no fuels”

See the syntax here

assert Expression[, Arguments]

Example:
Create a fuel.py file with below function

def fuelLevel(fuel):
   assert (fuel > 0),"Sorry no fuel in the system"
   print(fuel)

   
   
fuelLevel(4)
fuelLevel(0)

Run from command prompt

assertion error python

php code to check if function exists or not

when we are doing coding a project,their is a chance of misspelling the function name it will end up with an error function does not exists error php,so before calling a function you have to check if the function is already define or not,for we have simple php code to check if function exists or not here is the syntax

function_exists(FUNCTION_NAME_HERE);

This will Return true if the function is defined

e.g

if(function_exists('new_func')){
  //new_func is defined

  new_func();  call that function  
}

This function we can use at the time of defining a function,otherwise you will get an error message saying already the function “new_func” is defined

So for before all fucntion declare case you have to use function_exists(‘new_func’) fucntion to double confirm no where the function is define more than one times

see the error message here

php-code-to-check-if-function-exists-or-not

if(!function_exists('new_func')){
 function new_func()
 {
  echo "php code to check if function exists or not";	 
 }
}

Out put
php code to check if function exists or not