Reputation: 567
I am making (learning) a simple web app using flask. I am not using the templates for css input. I'm directly coding the css using the 'style' tag in the jinja2 template. But the style tag is not working. Even though using inspect element in chrome i can see the style tag being rendered?
{% extends "base.html" %}
{% block style %}
body{
line-height:1.5;
background-color:gray;
font-size:10px;
}
{% endblock %}
<html>
<head>
{% if title %}
<title>{{ title }}</title>
{% else %}
<title>Welcome to Micro-blogger Index page!</title>
{% endif %}
<style>
{% block style %}{% endblock %}
</style>
</head>
<body>
<h1><a href='/'>Index</a>
<br/>
{% block content %}{% endblock %}
</body>
</html>
Edit: By not working i mean like the background color is still white and font size & line-height are not as coded.
Edit:When I put the css element in the base.html , the rendering works. But when i pass it through variable in the index.html file the prev. mentioned thing happens. Yeah i could link a stylesheet or pass the css element from the base.html template , but what would i do in a scenario (i hope i don't have to , maybe for debug purposes) when i have two html docs both inheriting from same base.html but need to have different css attributes (like different background color etc.)
Upvotes: 0
Views: 4793
Reputation: 11
What is the need to add style using the ninja template custom tags. Instead you can directly use the style tag. Here is the code.
<style>
body{
line-height:1.5;
background-color:gray;
font-size:10px;
}
</style>
and you can directly place it wherever you want.
Upvotes: 1