zmbq
zmbq

Reputation: 39023

Django {% url %} tag for the currently rendering view

I'm developing a website that lets the user read books, displayed in different ways. For example, I have the following URLs:

Upvotes: 0

Views: 60

Answers (1)

Henrik Andersson
Henrik Andersson

Reputation: 47202

No, there is not, since that would introduce a very stronger coupling between view and template and that's usually a bad idea.

But this sounds like you want to parameterize the color, doesn't it? Then you can pass the color to the navigation or wherever you want to.

def read_in_color(request, color, book, chapter):
    if color == "white":
        return render_to_response("whitetemplate")
    if color == "pink":
        return render_to_response("pinktemplate")

Then in your templates

{% url "app.views.read_in_color" color="pink" book="Good Book" chapter=1 %}

Upvotes: 2

Related Questions