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 6652005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:04:45+00:00 2026-05-26T01:04:45+00:00

I want to take the URL from request.path in a template and do a

  • 0

I want to take the URL from request.path in a template and do a test on just the first word. If my URL is this:

/estimates/commercial

I want to somehow remove the commercial from the request.path. I was hoping this is possible within the template, too, since I need to do this check at every page.

Is this possible within my Django template?

EDIT – for clarification

The purpose of this is to highlight the navigation link based on what page is currently being viewed. I have a main nav and a sub nav and I want to highlight as follows:

main nav           --> [Systems][Estimates]
"Systems" sub nav ---> [New][Details][Invoives]

If I am in the Details section of the Systems section, I want the words System and Details to be a different colour, or underlined, or something.

  • 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-26T01:04:46+00:00Added an answer on May 26, 2026 at 1:04 am

    Your options are:

    1. Write a ContextProcessor

    2. Write a custom template filter. I’d reccomend just writing a split template filter and then using the join and slice filters to get the desired affect. However, it might be easier to just write a filter that does the whole thing.

    Truthfully I’d consider #1 to be the better option. You are using context processors already right? If not, now is the time =)

    def somename(request):
        return { 'some_context_var': request.path.split('/')[:-1] }
    

    Edit:

    If your path was /something/foo/bar/estimates/commercial/

    def somename(request):
        primary, secondary  = request.path.split('/')[-2:]
        return { 'primary_name': primary, 'secondary_name': secondary }
    

    would give you 2 context vars with ‘estimates’ and ‘commercial’ as their values. This idea is pretty easy to expand, or even make more abstract and allow an arbitrary number of context variables being added.

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

Sidebar

Related Questions

I just want a function that can take 2 parameters: the URL to POST
I am using WAMP. I want to take background image URL from my database
i have a requirement, i want to take URL of image from user and
I want to take a file from disk and upload it into an Oracle
I can get the view function from request.path : from django.core.urlresolvers import resolve view_func,
If I were to take a query string from an incoming request HTTP request
Let's take the Django tutorial. In the first part we can find this model:
I want to block access to a url from everything except for iis usr
I want to take html, including the text and images and turn it into
I want to take the value stored in a 32 bit unsigned int, put

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.