On 27/03/2018 3:09 PM, prince gosavi wrote:
> I am working on a project where I need to have different styles for
> different templates.
> I have a base.html template which gets extended in other templates.
> Following is the snippet:
> |
> base.html
> {%load static%}
> <!DOCTYPE html>
> <html>
> <head>
> <meta charset="utf-8">
> <title>Recommendation</title>
> <link rel="stylesheet" type="text/css"
> href="{%static'main_app/main.css'%}">
> |
In the base.html add as many blocks as you like to be filled by other
templates extending this one. For example, you want to add different css
stylesheets in different templates later in the flow of pages ...
{% block extrastyle %}{% endblock %}
If you insert this extrastyle block after the "master" stylesheet, any
earlier styles can be changed
> |
> </head>
> <body>
> <div class="sexy">
> {% block css%}
>
> {% endblock%}
> {% block nav %}
> <ul id='nav'>
> <li>{% block nav-help %} <a href="{%url 'help'%}">Help</a> {%
> endblock %}</li>
> <li>{% block nav-index %} <a href="{%url 'index'%}">Home</a>
> {% endblock %}</li>
> <li>{% block nav-query %} <a href="{%url 'query'%}">Query</a>
> {% endblock %}</li>
> </ul>
> {% endblock %}
> </div>
> <div class="sexy-color">
> {% block content %}
>
> {% endblock %}
> </div>
> </body>
> </html>
> |
>
> Now here is the other template:
> |
> query.html
> {%extends"base.html"%}
> {%load static%}
>
> |
|If you are extending another template you rely entirely on filling
pre-existing blocks. That means you don't need any html like this ...|
> |
> <!DOCTYPE html>
> <html>
> <head>
> <meta charset="utf-8">
> <title>Query</title>
> <link rel="stylesheet" href="{% static 'main_app/query.css' %}">
> </head>
> <body>
> |
|... down to here.
However, you can ...
{% block title %}Query{% endblock %}
... and also add another stylesheet with ...
{% block extrastyle %}{{ block.super }}|
||<link rel="stylesheet" href="{% static 'main_app/query.css' %}">
{% endblock %}
The block.super introduces any pre-existing content of that block in the
template you are extending.
HTH
Mike
||
> |
> {% block nav-query %}<strong class="nav-active">Query</strong>{%
> endblock %}
> <div class="cool-padding">
> {% block content %}
> <form method="post" action='/result/'>
> {% csrf_token %}
> {{ form }}
> <input type="submit" value="Submit" />
> </form>
> {% endblock %}
> </div>
> </body>
> </html>
> Enter code here...
> |
>
> I want query.html to have its own css(query.css):
> |
> main.css
> .sexy{
> background-color:red;
> }
>
> .sexy-color{
> color:yellow;
> }
>
> |
>
>
> And query.css is:
> |
> query.css
> .cool-padding{
> padding:10px,10px,10px,10px;
> }
> Entercode here...
> |
>
> The problem is i am unable to add 'query.css' to the query.html thus
> unable to use the css code please help.
>
> Regards.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
django-users...@googlegroups.com
> <mailto:
django-users...@googlegroups.com>.
> To post to this group, send email to
django...@googlegroups.com
> <mailto:
django...@googlegroups.com>.
> Visit this group at
https://groups.google.com/group/django-users.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/django-users/387e77b9-9340-46e0-bc04-e0fac3175ea3%40googlegroups.com
> <
https://groups.google.com/d/msgid/django-users/387e77b9-9340-46e0-bc04-e0fac3175ea3%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit
https://groups.google.com/d/optout.