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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:15:40+00:00 2026-05-26T23:15:40+00:00

I have following routs: url(r’^future/programs/$’, main.programs, {‘period’: ‘future’}), url(r’^past/programs/$’, main.programs, {‘period’: ‘past’}), When I

  • 0

I have following routs:

url(r'^future/programs/$', main.programs, {'period': 'future'}),
url(r'^past/programs/$', main.programs, {'period': 'past'}),

When I try to display link in template, using template tag url like this

{% url main.views.main.programs %}

I always get link /past/programs/. When I try like this

{% url main.views.main.programs period="future" %}

I get an error:

Caught NoReverseMatch while rendering: Reverse for
‘main.views.main.programs’ with arguments ‘()’ and keyword arguments
‘{‘period’: u’future’}’ not found.

How i can display link to /future/programs/?

  • 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-26T23:15:41+00:00Added an answer on May 26, 2026 at 11:15 pm

    I think you might want to approach it with one single url pattern:

    url(r'^(?P(<period>[\w]+)/programs/$', main.views.programs),
    

    and in your view:

    def programs(request, period):
        if period == 'future':
            ...
        elif period == 'past':
            ...
    

    and in templates:

    {% url main.views.main.programs period="future" %}
    

    In your approach, you are mistaking the forward flow with the reverse flow, i.e. the extra keyword arguments of the url conf with the keyword arguments that are passed to match a pattern.

    The former is extra data you are allowed to pass to a view when it is matched (i.e. when a user goes to /future/programs/, the pattern is matched and period=future is passed to the view), the latter is the actual data used to match the url (i.e. the period=future is passed to the reverse() function which tries to match a pattern that excepts those keyword arguments – which you haven’t outlined)

    Edit:

    A more appropriate pattern to use in your url would be something like:

    url(r'^(?P(<period>past|future)/programs/$', main.views.programs),
    

    where the selection could only be ‘past’ or ‘future’. This is fine for incoming urls, but django’s reverse() function (which is used in the url template tag) can’t handle alternative choices:

    https://docs.djangoproject.com/en/dev/topics/http/urls/#reverse

    The main restriction at the moment is that the pattern cannot contain alternative choices using the vertical bar (“|”) character.

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

Sidebar

Related Questions

I have the following route: routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with
I have the following case where I want to accept the following routs '/type/view/23'
I have the following route: routes.MapRoute( Search, // Route name Search/{affiliateId}, // URL with
I have the following route: routes.MapRoute( edit_product, // Route name Product/Edit/{productId}, // URL with
I have the following routes configuration in a Symfony application: label: url: /label param:
Suppose I have the following routing routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL
I have the following route defined: routes.MapRoute(name: StateResults, url: {state}/{searchTerm}, defaults: new { controller
I have the following routes defined in my Global.asax: routes.MapRoute(name: Home, url: , defaults:
I have the following code: Url.Action(Index, Home, new {param1 = Model.Param1, param2 = Model.Param2}
I have the following route rule set in my config/routes.php: $route[add/url/(:any)] = add/url/$1/$2/$3; This

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.