Django (Day 7) : Linking HTML & CSS Files to Django

 


Go to templates Folder

Create New HTML file BaseTemplate.html


<!DOCTYPE html>

{% load static %}

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title> STUDENT SYSTEM</title>

    <link rel="stylesheet" href="{% static 'test_app/style.css'%}">

</head>

<body>

<h1>Header</h1>

<!-- Add Your Images-->

<!-- <br> For Break Line -->

{% block content %}

{% endblock %}

<h2>Footer</h2>

</body>

</html>


Update templates/index.html


{% extends "BaseTemplate.html" %}

{% block content %}

<body>

{% for student in students %}

<a href="{% url 'student' student.id %}">{{student.name}}</a><br>

{% endfor %}


<form action="{% url 'createStudent' %}" method="POST">

    {% csrf_token %}

    {{form.as_p}}

    <input type="submit" value="Submit">

</form>

</body>

{% endblock %}


Update templates/Student.html


{% extends "BaseTemplate.html" %}

{% block content %}

<body>

{{student.name}}<br>

{{student.age}}<br>

{{student.branch}}<br>

{{student.marks}}<br>

{{student.college}}<br>

{% if students.marks >= 90 %}

<h1>PASS</h1>

{% else %}

<h1>FAIL</h1>

{% endif %}

</body>

{% endblock %}


Go to test_app folder 

Create new Directory static

In static Create new Directory test_app 

In test_app create new css file with name as style.css


/*

   *{

    background-color: black;

    color: white;

}

*/


My CSS is commented you can write whatever u wish

Go to django_project/settings.py 


In the end you'll see 

STATIC_URL = 'static/'


Update it to 

STATIC_URL = '/static/'


Run python manage.py makemigrations

Run python manage.py migrate 

Run python manage.py runserver


--- The End ---


Note: For any further doubts Contact Hemanth Sir.


Comments

Popular posts from this blog

Django (Day 1)

Django (Day 2)

Django (Day 3)