Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 984595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:02:31+00:00 2026-05-16T05:02:31+00:00

I have a couple of views which are rendering the same template and I

  • 0

I have a couple of views which are rendering the same template and I have some {% url %} tags into that template which needs to point to different location based on the current view. Is there any context variable which gives the name of the view(for named urls), like view-1 view-2, so in my template I can use it like this:

{% url url-name %}

It is also possible to pass additional information to the template so I can understand which view is called. But that would not be an elegant solution I guess.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:02:31+00:00Added an answer on May 16, 2026 at 5:02 am

    It is also possible to pass additional information to the template so I can understand which
    view is called. But that would not be an elegant solution I guess.

    Sure it is. Here’s an example:

    def view1(request, form_class=MyForm, template_name='myapp/page.html'):
        # app code here
        this_url = reverse('view1')
        render_to_response(template_name, locals(), RequestContext(request))
    
    def view2(request, form_class=MyForm, template_name='myapp/page.html'):
        # app code here
        this_url = reverse('view2')
        render_to_response(template_name, locals(), RequestContext(request))
    

    myapp/page.html:

    <a href="{{ this_url }}">Webpage</a>
    

    You can also create your own url tag called, say, dynurl that takes the first argument as a variable instead of as the view name:

    def view2(request, form_class=MyForm, template_name='myapp/page2.html'):
        # app code here
        this_view = 'view2'
        render_to_response(template_name, locals(), RequestContext(request))
    

    myapp/page.html:

    {% load dynurl_tags %}
    <a href="{% dynurl this_view %}">Webpage</a>
    

    You haven’t exactly explained why you want a link to the current view, though. Is it in order to link to the same page? There are a couple of ways to do that:

    <a href="">technically this points back to the same page</a>
    <a href="{{ request.path }}">this url is the full path before the query string</a>
    <a href="{{ request.get_full_path }}">this url is the full path plus the query string</a>
    

    I think it would be useful to think about what the key differences are between the two views and come up with a variable that describes their difference. Then use that variable in the template to determine the new URLs.

    For more complex problems you might want to look at Pinax groups and how they implement a {% groupurl %} tag. Basically it lets you duplicate all the urls of a given app and pass in a “group” variable that’s used to create a special group-based reverse lookup for urls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple of views which present data from a CoreData entity in
I have a couple of Javascript libraries of my own that do some nice
I have a list view which has a couple of views within it, I
I have a couple of modal views that have been working just fine and
I have a couple of views which use the SELECT CASE syntax.However when I
My story is: I have a couple of forms in separately views that post
I have an application with many views. I want only a couple of the
I have a view model with a couple of properties that are not displaying
I have couple of dozen pieces of data that I need to save and
I have couple questions regarding some C++ rules. Why am I able to call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.