Understanding Templates In Django

Search for a command to run...

No comments yet. Be the first to comment.
This is a basic Django tutorial in which we will create an Authentication App, from scratch in Django 2.0 and Learn the Fundamental concepts of Django Framework.
In this section, we will learn what are URLs in Django and how to create them and link them with the view functions that we have created in views.py file. So in our previous section, we have successfully created our Templates. Let's create URLs for e...
You've done it. I've done it. We've all done it.

Your AI Agent Has Amnesia. ByteRover Fixes It — Without Vectors Let's see how to built a customer support agent that remembers everything — using plain markdown files, BM25 search, zero embeddings, a

My GenAI cohort kicked off today, and what a first day! Right away we were reminded that AI isn’t magic — at its core, models like Generative Pretrained Transformers (GPT) are doing one simple thing:

Hello Folks👋, I Recently got Graduated🎓 in 2020, yep in the Pandemic. We all hit very hard by this Corona Pandemic and we all got stuck at home for very long. We all realize the Importance of Socializing, Fitness (Physically as well Mentally), Diet...

So after learning the basic commands of git in our previous section, let's see Git in action. If you already have a project to track your files then you can skip this section and if not then continue. Initializing a Repository from Non-existing Dire...

In this section, we will learn what are Templates in Django and where to store templates or HTML pages in Django. Along with Templates, we will also see how to handle and store Static files in Django. Static files include Javascript, CSS, Images.
So in our previous Section, we have successfully created our views in the views.py file. Let's create templates for each view in this section.
Django makes it possible to separate python and HTML, the python goes in views and HTML goes in templates. To link the two, Django relies on the render function and the Django Template language.
Now create a template folder inside accounts/ folder and inside template folder create registration folder and inside registration folder create signup.html and an index.html file. This folder will store all of your HTML files. The directory structure should look like below:
account/
templates/
registration/
signup.html
index.html
Also, create another folder inside the account app named it static and create an account folder inside the static/ folder and create a css folder inside the account folder(inner) and download the style.css file from here and move inside /static/account/css/ folder.
Now open the signup.htmland put the following code inside it:
<!-- signup.html -->
<!DOCTYPE html>
<html>
<head>
<title>Sign Up</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" type="image/png" href="/static/logo.png"/>
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<link href="/static/account/css/style.css" rel="stylesheet" type="text/css" media="all" />
<link href="//fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i" rel="stylesheet">
</head>
<body>
<div class="main-w3layouts wrapper">
<h1>SignUp</h1>
<div class="main-agileinfo">
<div class="agileits-top">
<form method="post">
{% csrf_token %}
{{form.as_p}}
<div class="wthree-text">
<label class="anim">
<input type="checkbox" class="checkbox" required="">
<span>I Agree To The Terms & Conditions</span>
</label>
<div class="clear"> </div>
</div>
<input type="submit" value="SIGNUP">
</form>
<p>Already have an Account? <a href="#"> Login Now!</a></p>
</div>
</div>
<div class="w3copyright-agile">
<p>© 2020 TeachmeBro SignUp Form. All rights reserved | Design by Team TeachmeBro</p>
</div>
<ul class="w3lsg-bubbles">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<!-- //main -->
</body>
</html>
Now open the index.html and put the following code inside it:
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Home</title>
</head>
<body>
{% if user.is_authenticated %}
<h1>Welcome, {{user.username}} You Successfully Logged In</h1>
{% else %}
<h1><p><a href="{% url 'signup' %}"> Signup</a></p></h1>
{% endif %}
</body>
</html>
That's it! we have written our first templates. Next, we only need to create a URL mapping for each view function, so will see it in our next tutorial.
In this section, we have successfullywrittenTemplates in Django. So in the next section, we will see what are **URLs** in Django.