templates and static files in django

---------------------------------------------- templates---------------------------------------------------------------

cmd>mkdir templates

#views.py

from django.shortcuts import render

# Create your views here.
def home(request):
    return render(request,'index.html')


#setting.py

'DIRS': [os.path.join(BASE_DIR,'templates')],

---------------------------------------------------static-------------------------------------------------------------------

 #mkdir static "cmd>static/index.html"

body{
    background-color: green;
}


#setting.py

STATIC_URL = 'static/'
STATICFILES_DIRS=[
    os.path.join(BASE_DIR,'static')
    ]



#linked html file (index.html)

{% load static %}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="{% static 'index.css' %}" />
  </head>
  <body></body>
</html>

Comments