Django KeyPoints

Want to Register All the models in Django Admin Panel(

import django.apps


for model in models:
except admin.sites.AlreadyRegistered:

Want to UnRegister model in Django Admin Panel(

Render A html page form passing the list view after submission(add.html)

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Add Item</title>
<form action="{% url 'add_bidding_item' %}" method="post">
{% csrf_token %}

<div class="form-group">
<label>Item Name</label>
<input name="item_name" type="text" class="form-control" required>
<div class="form-group">
<input name="item_price" type="text" class="form-control" required>
<div class="form-group">
<select name="item_vendor_name">
{% for i in items %}
<option value="{{}}" >{{i.vendor_name}}</option>
{% endfor %}
<input type="submit" class="btn btn-success" value="Create Item">

{% if message %}
{% endif %}
Connect Django with MySql ( --pip install mysqlclient
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'put your database name',
'USER': 'root',
'PASSWORD': 'your Mysql Password',
Connect templates and static file (
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR, "templates"],
'APP_DIRS': True,
'context_processors': [

STATIC_URL = 'static/'

BASE_DIR / "static",

Change Date Format (
USE_L10N = False
Change Time Format (
TIME_ZONE = 'Asia/Kolkata'

Display Django Message in html page

{% if messages %}
{% for message in messages %}
<div class="alert {{message.tags}}" id="message_container">
<span class="closebtn" onclick="'none';">&times;</span>
<strong>{{ message }}!!</strong>
{% endfor %}
{% endif %}
style.css (Message styling)
.alert {
padding: 5px;
background-color: #f44336;
color: white;
border-radius: 5px;
text-align: center;
opacity: 2;
transition: opacity 0.6s;

.alert.success {background-color: #04AA6D;} {background-color: #2196F3;}
.alert.warning {background-color: #ff9800;}
.alert.error {background-color: #7676a7;}

.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;

.closebtn:hover {
color: black;
script.js(For flash message -messsge disappear after 3 sec)
var message_ele = document.getElementById("message_container");

setTimeout(function(){ = "none";
}, 3000);
// Timeout is 3 sec, you can change it

Leave a Comment

Your email address will not be published. Required fields are marked *