Creating "LOGO" on our website !!

In this Chapter, we're going to learn about creating LOGO. 

when you go to website, you see the logo bar on the top or at the bottom,, like Google LOGO even when you search something it remains at every pages. 

How does it happen, should we make a copy of the logo at every single page ?  Django makes things way easier!  

Let's make the logo on our website ! 


First you need to create folder "templates"

I made inside "Newproject" folder where our project is located at. 

and make new file  "home.html"  and put this sentence 

<h1>Home Template</h1>

Also make "room.html" file at the same direction, saying;

<h1>Room Template</h1>

now we have two templates.  we need to return this inside of our views. 

First thing we need to do is let Django know that we have "templates" now. 

project folder 
this is my path;  (mysite/ setting.py) 
 

    we add     "BASE_DIR / 'templates'  " into TEMPLATES

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            BASE_DIR / 'templates'


And going back to the views.py, we actually need to create "render" function, which needs 2 parameters. the parameters are "request" and "specify the template name"  In this case, we have home.html

I deleted HttpResponse and made two function following;

from django.shortcuts import render

# Create your views here.

def home(request):
    return render(request, 'home.html')

def room(request):
    return render(request, 'room.html')
 


Add in a navigation bar, adding all those tags, styling, and then if we change out one link in the navigation bar, we're going to need to go back to all the templates. so we can make inheritance template and include sections of templates inside of other templates. 

I'm going to make another file inside of templates folder, naming "navbar.html" 

<a href="/">
    <h1>LOGO</h1>
</a>

<hr>

<a href>: going to send the user back to the home page we'll just direct to a forward slash and then ; it can be image or letters, especially "LOGO" here 

Now we're going back to home.html, use a template tag curly braces and percent symbols like this 

{% %}  

{% include 'navbar.html' %}

<h1>Home Template</h1>

{% include 'navbar.html' %}
means we're going to  include navbar template into home template.  Let's run the homepage again


You see the "LOGO"  ! 


if you want to make the logo on "/room" page as well , go to the room template and add the same thing,,

Let's make multiple logos here like this  

{% include 'navbar.html' %}

<h1>Room Template</h1>

{% include 'navbar.html' %}
{% include 'navbar.html' %}

and run again !  /room


Now you see "Multiple LOGO" here !  


I'm going to show you how to make them cool next time :) 



Popular posts from this blog

[Python] Dictionary

[Visual Design 2/3]

[JavaScript] For loop , Function