2

I have my URL defined as follows:

(r'^article/edit/(.*)/$', 'mysite.views.edit_article')

And the function defined as:

def edit_article(request, article_id):

However, it seems that any request to this page results in the wrong value being passed in for article_id. If I redefine my URL as

(r'^article/(.*)/$', 'mysite.views.edit_article')

Minus the "edit/" it seems to work. Any suggestions on how to fix this?

2
  • 1
    What "wrong value" are you getting? Commented Nov 9, 2011 at 18:43
  • In what way is it wrong? What is the actual value for article_id vs the expected value? Commented Nov 9, 2011 at 18:43

1 Answer 1

3

Try this:

url (r'^article/edit/(?P<article_id>\d+)$', 'mysite.views.edit_article'),

Take a look at the Named Groups in the Django documentation

Sign up to request clarification or add additional context in comments.

1 Comment

You don't have to name the parameter - if you don't, it will be passed positionally, to the first argument in the function (after request). Since his view only has one additional argument, it should work either way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.