Python Forum

Full Version: changing stylesheet according to variable in views
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
will be Grateful for any lead to carry on my road into Django.

## Trying to change the stylesheet page according to a variable in the views.
## Only Works for home page, and other pages didnt work.

any clues? Thanks in Advance.

# Head html Page:
<meta charset="UTF-8" />
{% if page_styl == 'home-page' %}
	<link rel="stylesheet" href="{% static 'css/layout.css' %}" />
{% else %}
	<link rel="stylesheet" href="{% static 'css/{{ page_styl }}.css' %}" />
{% endif %}
<title>A.M.W Store | {{ page }}</title>
# Views Example:
from django.shortcuts import render
def index(request):
    context = {
        'page': 'Contact Us',
        'page_styl': 'contact'
    }
    return render(request, 'contact/contact.html', context)