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

  • Home
  • SEARCH
  • 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 534969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:40:03+00:00 2026-05-13T09:40:03+00:00

I know that I can pass object values through a URL pattern and use

  • 0

I know that I can pass object values through a URL pattern and use them in view functions. For instance:

(r'^edit/(?P<id>\w+)/', edit_entry),

can be utilized like:

def edit_entry(request, id):
        if request.method == 'POST':
                a=Entry.objects.get(pk=id)
                form = EntryForm(request.POST, instance=a)
                if form.is_valid():
                        form.save()
                        return HttpResponseRedirect('/contact/display/%s/' % id)
        else:
                a=Entry.objects.get(pk=id)
                form = EntryForm(instance=a)
        return render_to_response('edit_contact.html', {'form': form})

But how do I pass a value from a model field (other than “id”) in the url? For instance, I have an abstract base model with a field “job_number” that is shared by child models “OrderForm” and “SpecReport”. I want to click on the “job_number” on the order form and call the Spec Report for that same job number. I can create an

href="/../specifications/{{ record.job_number }}

to pass the info to the url, but I already know that this regex syntax is incorrect:

(r'^specifications/(?P<**job_number**>\w+)/', display_specs),

nor can I capture the job_number in the view the same way I could an id:

def display_specs(request, job_number):
    records = SpecReport.objects.filter(pk=job_number)
    tpl = 'display.html'
    return render_to_response(tpl, {'records': records })

Is there an easy approach to this or is it more complicated than I think it is?

the amended code is as follows:

(r'^specdisplay/?agencyID=12/', display_specs),

and:

def display_specs(request, agencyID):
    agencyID= request.GET.get('agencyID')
    records = ProductionSpecs.objects.filter(pk=id)
    tpl = 'display_specs.html'
    return render_to_response(tpl, {'records': records })

not sure how to filter. pk is no longer applicable.

  • 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-13T09:40:03+00:00Added an answer on May 13, 2026 at 9:40 am

    Yes, you are making this a little more complicated that it is.

    In your urls.py you have:

    (r'^edit/(?P<id>\w+)/', edit_entry),
    

    Now you just need to add the almost identical expression for display_specs:

    (r'^specifications/(?P<job_number>\w+)/', display_specs),
    

    Parenthesis in the regex identifies a group and the (?P<name>...) defines a named group which will be named name. This name is the parameter to your view.

    Thus, your view will now look like:

    def display_specs(request, job_number):
       ...
    

    Finally, even though this will work, when you redirect to the view, instead of using:

    HttpResponseRedirect('/path/to/view/%s/' % job_number)
    

    Use the more DRY:

    HttpResponseRedirect(
        reverse('display_specs', kwargs={'job_number': a.job_number}))
    

    Now if you decide to change your resource paths your redirect won’t break.

    For this to work you need to start using named urls in your urlconf like this:

    url(r'^specifications/(?P<job_number>\w+)/', display_specs, name='display_specs'),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 269k
  • Answers 270k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Not PHP, but you could use this as a open-source… May 13, 2026 at 1:24 pm
  • Editorial Team
    Editorial Team added an answer So the problem is really with properties going into the… May 13, 2026 at 1:24 pm
  • Editorial Team
    Editorial Team added an answer You seem to have them mixed up. You are right… May 13, 2026 at 1:24 pm

Related Questions

Here's the situation: I would like to iterate through a table with input controls,
I am trying to extend the partial classes that the entity framework creates so
I have an issue with manipulating large number of record objects of type ActiveRecord
This is using Google App Engine. I am not sure if this is applicable
I have a fairly large CRUD WinForm app that has numerous objects. Person, Enrollment,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.