Here's the content of my views.py
file:
from django.shortcuts import render
def page(request):
css = 'temp/css.css'
return render(request, 'temp/index.html', {'css': css})
and this is the content of templates/temp/index.html
:
{% load static %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="{% static '{{ css|safe }}' %}">
</head>
<body>
Hello Page
</body>
</html>
now look at the contents of static/temp/css.css
:
* {
width: 100vw;
height: 100vh;
background: red;
}
Upon rendering, the source code of the page appears as follows:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/static/%7B%7B%20css%7Csafe%20%7D%7D">
</head>
<body>
Hello Page
</body>
</html>
However, I am expecting it to show:
...
<link rel="stylesheet" type="text/css" href="/static/temp/css.css">
...
Why isn't it working as expected? Is there a way to achieve this? How can I link a static file based on the path provided in the context
within HTML?