Tobi Olasimbo
11 min readSep 19, 2021

BUILDING HOTEL MANAGEMENT SYSTEM IN DJANGO

Setup
In this tutorial we will discuss through a process of building an Hotel Management System. We will be using Python 3.9.6, and Django==3.2.7.

Firstly, let’s install the required modules within a virtual environment.
These modules are known as dependencies and they are stored in a file called requirements.txt.

```
//virtual environment and
//dependencies
mkvirtualenv myvenv5
pip install Django
pip install psycopg2-binary==2.9.1
```

Creating requirements.txt

```
// capture requirements to install
pip freeze > requirements.txt
// install requirements from requirements.txt
pip install -r requirements.txt
// or
$ env1/bin/pip freeze > requirements.txt
$ env2/bin/pip install -r requirements.txt
```

Creating a project

To create a project we should move to the directory where we would to store our code. For this we go to command line and use cd command. Then trigger the startproject command.

```
django-admin startproject hotelsystem
```
This command gives us a ‘hotelsystem’ directoy. The contents of this directory look like this:
```
manage.py
hotelsystem/
__init__.py
settings.py
urls.py
wsgi.py
```

Database setup

We used POSTGRESS database, The hotelsystem/settings.py file would already have the correct settings.
And to make sure that the concrete value of the sensitive information in the database is actually only populated and only plugged into the file after deployment. To do this we used the concept called ENVIRONMENT VARIABLES. This allow us to use a placeholder and then define a value for the given environment variable.And this is a feature built into python. So, doing this we need to import from the core os module.

```
import environ
import os
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': env('DATABASE_NAME'),
'USER': env('DATABASE_USER'),
'PASSWORD': env('DATABASE_PASS'),
'PORT': env('DATABASE_PORT'),
'HOST': env('DATABASE_HOST')
}
}
```

After this, we use the migrate command that created the needed database tables in regard to the django_hotelsystem/ settings.py file.

```
python manage.py migrate
```

Creating application

We created our Django applications. In this project, we created six(6) apps, namely authentication app, booking app, customer app, payment app and receptionist app.From the project's root directory, run the following command:

```
python manage.py startapp <name_of_app>
```

This created the basic structure of the applications, which looks like this:

```
<name_of_app>/
__init__.py
admin.py
apps.py
migrations/
__init__.py
models.py
tests.py
views.py
```

These files are as follows:

admin.py : This is where we registered our models to include them in the Django
administration site—using the Django admin site is optional.

apps.py: This includes the main configuration of the our applications.

migrations: This directory contains database migrations of our applications. Migrations allow Django to track our model changes and sync our database.

models.py: All Django applications need to have a models.py file, but this file can be left empty.

tests.py: This is where we added our tests for your application.

views.py: This is the logic of our applications; each view receives an HTTP request, processes it, and returns a response.

Activating our applications

In order for Django to keep track of our applications and be able to build database tables for their models, we have to activate it. In order to do this, we edited the settings.py file and added our apps to the INSTALLED_APPS setting. It looks like this:

```
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'authentication',
'booking',
'Receptionist',
'customer',
]
```

With this, Django recognise that our applications are active for this project and would be able to load their models.

Creating models

We open our ‘models.py’ file and start writing the models. The models.py file should look like this:

Model For Our authentication app


from django.db import models
class Customer(models.Model):
username=models.CharField(max_length=100)
password=models.CharField(max_length=100)
email=models.CharField(max_length=50)
profile_pic=models.ImageField(upload_to="media", height_field=None, width_field=None, max_length=None,blank=True)
phone_no=models.CharField(max_length=50)
address=models.TextField()
state=models.CharField(max_length=30,blank=True)
pin_code=models.IntegerField(blank=True)
def __str__(self):
return "Customer: "+self.username

class RoomManager(models.Model):
username=models.CharField(max_length=100)
password=models.CharField(max_length=100)
email=models.CharField(max_length=50)
profile_pic=models.ImageField(upload_to="media", height_field=None, width_field=None, max_length=None,blank=True)
phone_no=models.CharField(max_length=50)
gender=models.CharField(max_length=20)
def __str__(self):
return "Room Manager: "+self.username

Model For booking app:

```
from django.db import models
from authentication.models import Customer,RoomManager
from datetime import date
class Contact(models.Model):
name=models.CharField(max_length=100)
email=models.CharField(max_length=100)
message=models.TextField(max_length=2000)
def __str__(self):
return self.name
class Rooms(models.Model):
manager=models.ForeignKey(RoomManager, on_delete=models.CASCADE)
room_no=models.CharField(max_length=5, )
room_type=models.CharField(max_length=50)
is_available=models.BooleanField(default=True)
price=models.FloatField(default=1000.00)
no_of_days_advance=models.IntegerField()
start_date=models.DateField(auto_now=False, auto_now_add=False)
room_image=models.ImageField(upload_to="media", height_field=None, width_field=None, max_length=None,default='0.jpeg')
def __str__(self):
return "Room No: "+str(self.id)
'''
class RoomImage(models.Model):
room=models.ForeignKey(Rooms, on_delete=models.CASCADE)
room_image=models.ImageField(upload_to="media", height_field=None, width_field=None, max_length=None)
'''
class Booking(models.Model):
room_no=models.ForeignKey(Rooms, on_delete=models.CASCADE)
user_id=models.ForeignKey(Customer, on_delete=models.CASCADE)
start_day=models.DateField(auto_now=False, auto_now_add=False)
end_day=models.DateField(auto_now=False, auto_now_add=False)
amount=models.FloatField()
booked_on=models.DateTimeField(auto_now=True, auto_now_add=False)
def __str__(self):
return "Booking ID: "+str(self.id)
@property
def is_past_due(self):
return date.today()>self.end_day
```

Model For Payment app:


```
from django.db import models
import secrets
from .paystack import PayStack
#Create your models here.class Payment(models.Model):
amount = models.PositiveIntegerField()
ref = models.CharField(max_length= 200)
email = models.EmailField()
verified = models.BooleanField(default=False)
date_created = models.DateTimeField(auto_now_add=True)

class Meta:
ordering = ('-date_created',)

def __str__(self) -> str:
return f"Payment: {self.amount}"

def save(self, *args, **kwargs) -> None:
while not self.ref:
ref = secrets.token_urlsafe(50)
object_with_similar_ref = Payment.objects.filter(ref=ref)
if not object_with_similar_ref:
self.ref = ref
super().save(*args, **kwargs)

def amount_value(self) -> int:
return self.amount * 100

def verify_payment(self):
paystack = PayStack()
status, result = paystack.verify_payment(self.ref, self.amount)
if status:
if result['amount'] / 100 == self.amount:
self.verified = True
self.save()
if self.verified:
return True
return False

def __unicode__(self):
return self.name
```

Creating and applying migrations

Now that we have a data model for our applitions, we ran the makemigrations command which notify Django that new models have been created and those changes needs to be applied to the migration. Run migrate command to do the actual migration.


```
$ python manage.py makemigrations
$ python manage.py migrate
```

Activating models

We created urls.py files for each of our apps.

urls.py For authentication app:

```
from django.urls import path,include
from . import views
urlpatterns=[
path('login',views.user_login,name='user_login'),
path('login1',views.manager_login,name='manager_login'),
path('signup',views.user_signup,name='user_signup'),
path('signup1',views.manager_signup,name='manager_signup'),
path('dashboard/',include('customer.urls')),
path('dashboard1/',include('Receptionist.urls')),
path('add-room/',include('Receptionist.urls'))
]
```

urls.py For booking app:

```
from django.urls import path
from . import views
urlpatterns=[
path('',views.index,name='index'),
path('book',views.book,name='book'),
path('contact-us',views.contact,name='contact-us'),
path('book-now/<str:id>',views.book_now,name='book-now'),
path('cancel-room/<str:id>',views.cancel_room,name='cancel-room'),
path('delete-room/<str:id>',views.delete_room,name='delete-room'),
# path('confirm-now-booking',views.book_confirm,name="book_confirm"),
]```

urls.py For customer app:

```
from django.urls import path
from . import views
urlpatterns=[
path('',views.dashboard,name='user_dashboard'),
path('details/<int:id>/<int:booking_id>',views.details,name='user_details')
]
```

urls.py For payment app:

```
from django.urls import path
from . import views
urlpatterns=[
path('',views.dashboard,name='user_dashboard'),
path('details/<int:id>/<int:booking_id>',views.details,name='user_details')
]
```

urls.py For Receptionist app:


```
from django.urls import path
from . import views
urlpatterns = [
path('',views.dashboard,name="manager_dashboard"),
path('new/',views.add_room,name="add_room"),
path('update/<int:room_no>/',views.update_room,name="update_room"),
]
```

We go to hotelsystem/urls.py and include the apps urls.
It looks like this:

```
from django.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static
from authentication import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('booking.urls')),
path('user/',include('authentication.urls')),
path('manager/',include('authentication.urls')),
path('logout',views.logout,name='logout'),
path('api/',include('api.urls')),
path('',include('payment.urls'))
## path('payment/', include(('payment.urls', 'payment'), namespace='payment'))
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
```

Setting up the admin for each model in each app

For authentication app:

```from django.contrib import admin
from authentication.models import Customer, RoomManager
Contact,Rooms,Booking
## Register your models here.
admin.site.register(Customer)
admin.site.register(RoomManager)
```

For payment app:


```
from django.contrib import admin
from .models import Payment
admin.site.register(Payment)```

Writing urls to the views for each app

For authentication app:

```
views.py
from django.shortcuts import render,redirect
from .models import Customer,RoomManager
from django.contrib.auth.hashers import make_password,check_password
from django.contrib import messages
#mesages.info(request,'mail taken')
def user_login(request):
if request.session.get('username',None) and request.session.get('type',None)=='customer':
return redirect('user_dashboard')
if request.session.get('username',None) and request.session.get('type',None)=='manager':
return redirect('manager_dashboard')
if request.method=="POST":
username=request.POST['username']
password=request.POST['password']
if not len(username):
messages.warning(request,"Username field is empty")
redirect('user_login')
elif not len(password):
messages.warning(request,"Password field is empty")
redirect('user_login')
else:
pass
if Customer.objects.filter(username=username):
user=Customer.objects.filter(username=username)[0]
password_hash=user.password
res=check_password(password,password_hash)
if res==1:
request.session['username'] = username
request.session['type'] = 'customer'
return render(request,'booking/index.html',{})
else:
messages.warning(request,"Username or password is incorrect")
redirect('user_login')
else:
messages.warning(request,"No, Account exist for the given Username")
redirect('user_login')
else:
redirect('user_login')
return render(request,'login/user_login.html',{})

def manager_login(request):
if request.session.get('username',None) and request.session.get('type',None)=='customer':
return redirect('user_dashboard')
if request.session.get('username',None) and request.session.get('type',None)=='manager':
return redirect('manager_dashboard')
if request.method=="POST":
username=request.POST['username']
password=request.POST['password']
if not len(username):
messages.warning(request,"Username field is empty")
redirect('manager_login')
elif not len(password):
messages.warning(request,"Password field is empty")
redirect('manager_login')
else:
pass
if RoomManager.objects.filter(username=username):
user=RoomManager.objects.filter(username=username)[0]
password_hash=user.password
res=check_password(password,password_hash)
if res==1:
request.session['username'] = username
request.session['type'] = 'manager'
return render(request,'booking/index.html',{})
else:
messages.warning(request,"Username or password is incorrect")
redirect('manager_login')
else:
messages.warning(request,"No, Account exist for the given Username")
redirect('manager_login')
else:
redirect('manager_login')
return render(request,'login/manager_login.html',{})
def user_signup(request):
if request.session.get('username',None) and request.session.get('type',None)=='customer':
return redirect('user_dashboard')
if request.session.get('username',None) and request.session.get('type',None)=='manager':
return redirect('manager_dashboard')
if request.method=="POST":
username=request.POST['username']
email=request.POST['email']
if Customer.objects.filter(username=username) or Customer.objects.filter(email=email):
messages.warning(request,"Account already exist, please Login to continue")
else:
password=request.POST['password']
address=request.POST['address']
pin_code=request.POST['pin_code']
profile_pic=request.FILES.get('profile_pic',None)
phone_no=request.POST['phone_no']
state=request.POST['state']
error=[]
if(len(username)<3):
error.append(1)
messages.warning(request,"Username Field must be greater than 3 character.")
if(len(password)<5):
error.append(1)
messages.warning(request,"Password Field must be greater than 5 character.")
if(len(email)==0):
error.append(1)
messages.warning(request,"Email field can't be empty")
if(len(phone_no)!=10):
error.append(1)
messages.warning(request,"Valid Phone number is a 10 digit-integer.")
if(len(error)==0):
password_hash = make_password(password)
customer=Customer(username=username,password=password_hash,email=email,phone_no=phone_no,address=address,state=state,pin_code=pin_code,profile_pic=profile_pic)
customer.save()
messages.info(request,"Account Created Successfully, please Login to continue")
redirect('user_signup')
else:
redirect('user_signup')

else:
redirect('user_signup')
return render(request,'login/user_login.html',{})
def manager_signup(request):
if request.session.get('username',None) and request.session.get('type',None)=='customer':
return redirect('user_dashboard')
if request.session.get('username',None) and request.session.get('type',None)=='manager':
return redirect('manager_dashboard')
if request.method=="POST":
username=request.POST['username']
email=request.POST['email']
if RoomManager.objects.filter(username=username) or RoomManager.objects.filter(email=email):
messages.warning(request,"Account already exist, please Login to continue")
else:
password=request.POST['password']
profile_pic=request.FILES.get('profile_pic',None)
phone_no=request.POST['phone_no']
error=[]
if(len(username)<3):
error.append(1)
messages.warning(request,"Username Field must be greater than 3 character.")
if(len(password)<5):
error.append(1)
messages.warning(request,"Password Field must be greater than 5 character.")
if(len(email)==0):
error.append(1)
messages.warning(request,"Email field can't be empty")
if(len(phone_no)!=10):
error.append(1)
messages.warning(request,"Valid Phone number is a 10 digit-integer.")
if(len(error)==0):
password_hash = make_password(password)
r_manager=RoomManager(username=username,password=password_hash,email=email,phone_no=phone_no,profile_pic=profile_pic)
r_manager.save()
messages.info(request,"Account Created Successfully, Please login to continue")
redirect('manager_signup')
else:
redirect('manager_signup')

else:
redirect('user_signup')
return render(request,'login/manager_login.html',{})
def logout(request):
if request.session.get('username', None):
del request.session['username']
del request.session['type']
return render(request,"login/logout.html",{})
else:
return render(request,"login/user_login.html",{})
```

For booking app:

```
views.py
from django.shortcuts import render,redirect
from .models import Contact
from .models import Rooms,Booking
from authentication.models import Customer
from django.contrib import messages
from django.http import HttpResponse
import datetime
def index(request):
return render(request,'booking/index.html',{})
def contact(request):
if request.method=="GET":
return render(request,"contact/contact.html",{})
else:
username=request.POST['name']
email=request.POST['email']
message=request.POST['message']
data=Contact(name=username,email=email,message=message)
data.save()
return render(request,"contact/contact.html",{'message':'Thank you for contacting us.'})
def book(request):
if request.method=="POST":
start_date=request.POST['start_date']
end_date=request.POST['end_date']
request.session['start_date']=start_date
request.session['end_date']=end_date
start_date=datetime.datetime.strptime(start_date, "%d/%b/%Y").date()
end_date=datetime.datetime.strptime(end_date, "%d/%b/%Y").date()
no_of_days=(end_date-start_date).days
data=Rooms.objects.filter(is_available=True,no_of_days_advance__gte=no_of_days,start_date__lte=start_date)
request.session['no_of_days']=no_of_days
return render(request,'booking/book.html',{'data':data})
else:
return redirect('index')
def book_now(request,id):
if request.session.get("username",None) and request.session.get("type",None)=='customer':
if request.session.get("no_of_days",1):
no_of_days=request.session['no_of_days']
start_date=request.session['start_date']
end_date=request.session['end_date']
request.session['room_no']=id
data=Rooms.objects.get(room_no=id)
bill=data.price*int(no_of_days)
request.session['bill']=bill
roomManager=data.manager.username
return render(request,"booking/book-now.html",{"no_of_days":no_of_days,"room_no":id,"data":data,"bill":bill,"roomManager":roomManager,"start":start_date,"end":end_date})
else:
return redirect("index")
else:
next="book-now/"+id
return redirect('user_login')

def book_confirm(request):
room_no=request.session['room_no']
start_date=request.session['start_date']
end_date=request.session['end_date']
username=request.session['username']
user_id=Customer.objects.get(username=username)
room=Rooms.objects.get(room_no=room_no)
amount=request.session['bill']
start_date=datetime.datetime.strptime(start_date, "%d/%b/%Y").date()
end_date=datetime.datetime.strptime(end_date, "%d/%b/%Y").date()
data=Booking(room_no=room,start_day=start_date,end_day=end_date,amount=amount,user_id=user_id)
data.save()
room.is_available=False
room.save()
del request.session['start_date']
del request.session['end_date']
del request.session['bill']
del request.session['room_no']
messages.info(request,"Room has been successfully booked")
return redirect('user_dashboard')
def cancel_room(request,id):
data=Booking.objects.get(id=id)
room=data.room_no
room.is_available=True
room.save()
data.delete()
return HttpResponse("Booking Cancelled Successfully")
def delete_room(request,id):
data=Rooms.objects.get(id=id)
manager=data.manager.username
if manager==request.session['username']:
data.delete()
return HttpResponse("You have deleted the room successfully")
else:
return HttpResponse("Invalid Request")
```

For customer app:


```
views.py
from django.shortcuts import render,redirect
from authentication.models import Customer
from booking.models import Booking
import datetime
def dashboard(request):
if request.session.get('username',None) and request.session.get('type',None)=='manager':
return redirect('manager_dashboard')
if request.session.get('username',None) and request.session.get('type',None)=='customer':
username=request.session['username']
data=Customer.objects.get(username=username)
booking_data=Booking.objects.filter(user_id=data).order_by('-id')
counts=booking_data.filter(end_day__lt=datetime.datetime.now()).count()
available=len(booking_data)-counts
return render(request,"user_dash/index.html",{"data":booking_data,"count":counts,"available":available})
else:
return redirect("user_login")
def details(request,id,booking_id):
if not request.session.get('username',None):
return redirect('manager_login')
if request.session.get('username',None) and request.session.get('type',None)=='customer':
return redirect('user_dashboard')
try:
booking_data=Booking.objects.get(id=booking_id)
user=Customer.objects.get(id=id)
return render(request,"user_dash/details.html",{"user":user,"booking_data":booking_data})
except:
return redirect("/manager/dashboard1/")
```

For payment app:


```
views.py
from django.shortcuts import render
from django.http.request import HttpRequest
from django.http.response import HttpResponse
from django.shortcuts import get_object_or_404, redirect, render
from .import forms
from django.contrib import messages
from django.conf import settings
from .models import Payment
## Create your views here.def initiate_payment(request: HttpRequest) -> HttpResponse:
if request.method == "POST":
payment_form = forms.PaymentForm(request.POST)
if payment_form.is_valid():
payment = payment_form.save()
my_context = {'payment': payment,
'paystack_public_key': settings.PAYSTACK_PUBLIC_KEY}
return render(request, 'make_payment.html', my_context)
else:
payment_form = forms.PaymentForm()
context2 = {'payment_form': payment_form}
return render(request, 'payment/initiate_payment.html', context2)
def verify_payment(request: HttpRequest, ref: str) -> HttpResponse:
payment = get_object_or_404(Payment, ref=ref)
verified = payment.verify_payment()
if verified:
messages.success(request, "Verification Success")
else:
messages.error(request, "Verification Failed.")
return redirect('initiate-payment')
```

For Receptionist app:


```
from django.shortcuts import render,redirect
from authentication.models import RoomManager
from booking.models import Booking,Rooms
from datetime import date
from django.contrib import messages
import datetime
def dashboard(request):
if not request.session.get('username',None):
return redirect('manager_login')
if request.session.get('username',None) and request.session.get('type',None)=='customer':
return redirect('user_dashboard')
if request.session.get('username',None) and request.session.get('type',None)=='manager':
username=request.session['username']
data=RoomManager.objects.get(username=username)
room_data=data.rooms_set.all()
booked=room_data.filter(is_available=False).count()
print(booked)
return render(request,"manager_dash/index.html",{"room_data":room_data,"manager":data,"booked":booked})
else:
return redirect("manager_login")
def add_room(request):
if not request.session.get('username',None):
return redirect('manager_login')
if request.session.get('username',None) and request.session.get('type',None)=='customer':
return redirect('user_dashboard')
if request.method=="GET":
return render(request,"manager_dash/add-room.html",{})
else:
room_no=request.POST['room_no']
room_type=request.POST['room_type']
price=request.POST['price']
room_image=request.FILES.get('room_image',None)
no_of_days_advance=request.POST['no_of_days_advance']
start_day=request.POST['start_day']
error=[]
if(len(room_no)<1):
error.append(1)
messages.warning(request,"Room No Field must be atleast 3 digit like 100.")
if(len(room_type)<5):
error.append(1)
messages.warning(request,"Select a valid Room Type.")
if(len(price)<=2):
error.append(1)
messages.warning(request,"Please enter price")
if(len(no_of_days_advance)<1):
error.append(1)
messages.warning(request,"Please add valid no of days a user can book room in advance.")
if(len(start_day)<3):
error.append(1)
messages.warning(request,"Please add the starting day")
if(not len(error)):
manager=request.session['username']
manager=RoomManager.objects.get(username=manager)
room=Rooms(room_no=room_no,room_type=room_type,price=price,no_of_days_advance=no_of_days_advance,start_date=datetime.datetime.strptime(start_day, "%d %B, %Y").date(),room_image=room_image,manager=manager)
room.save()
messages.info(request,"Room Added Successfully")
return redirect('/manager/dashboard1/')
else:
return redirect('/user/add-room/new/')
def update_room(request,room_no):
if not request.session.get('username',None):
return redirect('manager_login')
if request.session.get('username',None) and request.session.get('type',None)=='customer':
return redirect('user_dashboard')
room=Rooms.objects.get(room_no=room_no)
if request.method=="GET":
return render(request,"manager_dash/edit-room.html",{"room":room})
else:
price=request.POST['price']
no_of_days_advance=request.POST['no_of_days_advance']
error=[]
if(len(price)<=2):
error.append(1)
messages.warning(request,"Please enter correct price")
if(len(no_of_days_advance)<1):
error.append(1)
messages.warning(request,"Please add valid no of days a user can book room in advance.")
if(not len(error)):
manager=request.session['username']
manager=RoomManager.objects.get(username=manager)
room.price=price
room.no_of_days_advance=no_of_days_advance
room.save()
messages.info(request,"Room Data Updated Successfully")
return redirect('/manager/dashboard1/')
else:
return redirect('/user/add-room/update/'+room.room_no,{"room":room})
```

Creating templates for you views
We have created views and URL patterns for our applications. Now, it's time to add templates to display posts in a user-friendly manner.
We created the following directories and files inside our applications directories:

```
templates/
base/
base.html
booking/
book-now.html
book.html
index-html
contact/
contact.html
login/
logout.html
manager_login.html
user_login.html
manage_dash/
add-room.html
edit-room.html
index.html
project/
base.html
initiate_payment.html
user_dash/
details.html
index.html
```

The preceding structure is the file structure for our templates.The base.html file will include the main HTML structure of the website and divide the content into the main content area and a sidebar.

```
{%load static %}
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Cookie&display=swap" rel="stylesheet">
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js'></script>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<style>
.dropdown-content
{
top: 53px !important;
width:190px !important;
}
</style>
<body>
<nav style="background-color: dodgerblue">
<div class="nav-wrapper container">
<a href="/" class="brand-logo center" style="font-family: 'arial';font-size:2rem"><i class="material-icons" style="font-size:2rem">hotel</i>Room Slotter </a>
<a href="#" data-activates="slide-out" class="button-collapse"><i class="material-icons">menu</i></a>

<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="/">Home</a></li>
<li><a href="/contact-us">Contact Us</a></li>
{% if not request.session.username %}
<li><a class="dropdown-button" href="#!" data-activates='dropdown1'>Login/Register<i class="material-icons right">arrow_drop_down</i></a></li>
{% else %}
<li><a class="dropdown-button" href="#!" data-activates='dropdown2'>Account<i class="material-icons right">arrow_drop_down</i></a></li>
{% endif %}
</ul>
</div>
</nav>
<ul id="slide-out" class="side-nav">

<li><a href="/">Home</a></li>
<li><a href="/contact-us">Contact Us</a></li>
<li class="no-padding">
<ul class="collapsible collapsible-accordion">
<li style="margin-left:18px">
<a class="collapsible-header">Account<i class="material-icons right">arrow_drop_down</i></a>
<div class="collapsible-body">
<ul>
{% if not request.session.username %}
<li><a href="/user/login" class="blue-text"><i class="material-icons left red-text text-lighten-2">person</i> Customer</a></li>
<li class="divider" tabindex="-1"></li>
<li><a href="/manager/login1" class="blue-text"><i class="material-icons left red-text text-lighten-2">room_service</i> Room Manager</a></li>
{% else %}
{% if request.session.type == 'customer' %}
<li><a href="/user/dashboard"><i class="material-icons left red-text text-lighten-2">dashboard</i> Dashboard</a></li>
{% else %}
<li><a href="/manager/dashboard1"><i class="material-icons left red-text text-lighten-2">dashboard</i> Dashboard</a></li>
{% endif %}
<li><a href="/logout"><i class="material-icons left red-text text-lighten-2">exit_to_app</i> Logout</a></li>
{% endif %}
</ul>
</div>
</li>
</ul>
</li>
</ul>
<ul id='dropdown1' class='dropdown-content'>
<li><a href="/user/login" class="blue-text"><i class="material-icons left red-text text-lighten-2">person</i> Customer</a></li>
<li class="divider" tabindex="-1"></li>
<li><a href="/manager/login1" class="blue-text"><i class="material-icons left red-text text-lighten-2">room_service</i> Room Manager</a></li>
</ul>
<ul id='dropdown2' class='dropdown-content'>
{% if request.session.type == 'customer' %}
<li><a href="/user/dashboard"> <i class="material-icons left red-text text-lighten-2">dashboard</i>Dashboard</a></li>
{% else %}
<li><a href="/manager/dashboard1"> <i class="material-icons left red-text text-lighten-2">dashboard</i>Dashboard</a></li>
{% endif %}
<li><a href="/logout"> <i class="material-icons left red-text text-lighten-2">exit_to_app</i>Logout</a></li>
</ul>
{% block content %}
{%endblock %}
<footer class="page-footer" style="background-color: dodgerblue">
<div class="container">
<div class="row">
<div class="col l6 s12">
<h4 class="white-text" style="font-family: 'Cookie';">Room Slots</h4>
<p class="grey-text text-lighten-4">Get your room booked in seconds with amazing offers.</p>
</div>
<div class="col l4 offset-l2 s12">
<h4 class="white-text" style="font-family:'Times New Roman'">Important Links</h4>
<ul>
<li><a class="grey-text text-lighten-3" href="/">Home</a></li>
<li><a class="grey-text text-lighten-3" href="/contact-us">Contact Us</a></li>
{% if not request.session.username %}
{% if request.session.type == 'customer' %}
<li><a class="grey-text text-lighten-3" href="/user/login">Customer</a></li>
{% else %}
<li><a class="grey-text text-lighten-3" href="/manager/login1">Room Manager</a></li>
{% endif %}
{% else %}
<li><a class="grey-text text-lighten-3" href="/logout">Logout</a></li>
{% endif %}
</ul>
</div>
</div>
</div>
<div class="footer-copyright">
<div class="container">
© 2021 All right reserved
</div>
</div>
</footer>
<!-- Compiled and minified JavaScript -->
<script>
$(".button-collapse").sideNav();
$('.dropdown-button').dropdown({
hover:true
}
);
</script>
</body>
</html>
```

The rest html files inherited from the base.html file.

Template tags control the rendering of the template and look like


```
{% tag %}.
```

Template variables get replaced with values when the template is rendered and look like

```
{{ variable }}.
```

Also the template static is serve by Django.

In summary, when a user initiate a request, this is directed to the urls.py file of the project. The path that matches the request is selected and this request goes to the urls.py of the app that corresponds to the path and this is carried to the views.py files of that same app. In the views.py, this is where the template is being render alongside with the context. And this context entails data from our model or a special message that is important to be display in the html page. This context could be a sting, list or dictionary.