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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:44:24+00:00 2026-06-09T03:44:24+00:00

In Django’s urls.py, I know that you can specify an optional parameter to pass

  • 0

In Django’s urls.py, I know that you can specify an optional parameter to pass to a view for a single url() object. My question is, is it possible to specify the same optional parameter and have it apply to every single url() inside a patterns() object.

  • 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-06-09T03:44:25+00:00Added an answer on June 9, 2026 at 3:44 am

    I don’t think so, but you can simply use a variable:

    d = { 'foo' : very_long_value }
    
    urlpatterns = patterns('',
        url('^aaaa/$', 'aaa', d),
        url('^bbbb/$', 'bbb', d),
        url('^cccc/$', 'ccc', d),
    )
    

    If you want to be able to add values to some urls on the fly, you can do the following:

    def add_dict(d, **kw):
        x = d.copy()
        x.update(kw)
        return x
    
    d = { 'foo' : very_long_argument }
    
    urlpatterns = patterns('',
        url('^aaaa/$', 'aaa', d),
        url('^bbbb/$', 'bbb', d),
        url('^cccc/$', 'ccc', add_dict(d, bar = 'xxx')),
    )
    

    Or alternatively you can write your own url wrapper:

    def my_url(regex, view, kwargs=None, name=None, prefix=''):
        if kwargs is None:
            kwargs = {}
        kwargs.update(foo = very_long_argument)
        return url(regex, view, kwargs, name, prefix)
    
    urlpatterns = patterns('',
        my_url('^aaaa/$', 'aaa'),
        my_url('^bbbb/$', 'bbb'),
        my_url('^cccc/$', 'ccc' { 'bar' : 'xxx'),
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Django url pattern that have a number parameter is: url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail') What will be
Django is telling me that my login view isn't returning an HttpResponse object: The
Django urlize docs say: The urlize filter also takes an optional parameter autoescape .
Django docs say that Context object is a stack: from django.template import Context c
Django view points to a function, which can be a problem if you want
[Django 1.0.2] I have a view set up like this: (r'^redirect/(?P<object_id>\d+)/(?P<url>.*)/$', 'django.views.generic.simple.redirect_to', {'content_type': SiteType},
Django's views documentation states that the default 500 view passes no variables to this
Django has a very handy test client /dummy web browser that one can use
from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('',
Django has the concept of filters that allow you to format values in views.

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.