variable {% url %} parameter

3 views
Skip to first unread message

Baurzhan Ismagulov

unread,
Dec 12, 2009, 12:15:00 PM12/12/09
to django...@googlegroups.com
Hello,

Another named URL question. I have the following pattern:

(r'^app/(?P<object_id>\d+)/$', create_update.update_object,
{'model': App}, 'app-edit'),

Now, using {% url 'app-edit' object.pk %} in a form throws
TemplateSyntaxError, mentioning "NoReverseMatch: Reverse for
'rc.'app-edit'' with arguments '(1,)' and keyword arguments '{}' not
found." in the value. Is passing a variable from the view the best way
to do that? Is there any other method (not necessarily named URLs) of
getting a URL without hardcoding it?

With kind regards,
--
Baurzhan Ismagulov
http://www.kz-easy.com/

bruno desthuilliers

unread,
Dec 14, 2009, 5:12:00 AM12/14/09
to Django users
On 12 déc, 18:15, Baurzhan Ismagulov <i...@radix50.net> wrote:
> Hello,
>
> Another named URL question. I have the following pattern:
>
>     (r'^app/(?P<object_id>\d+)/$', create_update.update_object,
>      {'model': App}, 'app-edit'),
>
> Now, using {% url 'app-edit' object.pk %} in a form throws
> TemplateSyntaxError, mentioning "NoReverseMatch: Reverse for
> 'rc.'app-edit'' with arguments '(1,)' and keyword arguments '{}' not
> found."

The above url works with a named (aka 'keyword') param 'object_id', so
you do have to use the same scheme withing the url tag, ie:

{% url 'app-edit' object_id=object.pk %}

HTH

Baurzhan Ismagulov

unread,
Dec 15, 2009, 10:36:48 AM12/15/09
to Django users
On Mon, Dec 14, 2009 at 02:12:00AM -0800, bruno desthuilliers wrote:
> > � � (r'^app/(?P<object_id>\d+)/$', create_update.update_object,
> > � � �{'model': App}, 'app-edit'),
> >
> > Now, using {% url 'app-edit' object.pk %} in a form throws
> > TemplateSyntaxError, mentioning "NoReverseMatch: Reverse for
> > 'rc.'app-edit'' with arguments '(1,)' and keyword arguments '{}' not
> > found."
>
> The above url works with a named (aka 'keyword') param 'object_id', so
> you do have to use the same scheme withing the url tag, ie:
>
> {% url 'app-edit' object_id=object.pk %}

Thanks for the tip. This results in TemplateSyntaxError with
"NoReverseMatch: Reverse for 'rc.'app-edit'' with arguments '()' and
keyword arguments '{'object_id': 1}' not found.". What am I doing
wrongly?

Daniel Roseman

unread,
Dec 15, 2009, 11:00:54 AM12/15/09
to Django users
On Dec 15, 3:36 pm, Baurzhan Ismagulov <i...@radix50.net> wrote:
> On Mon, Dec 14, 2009 at 02:12:00AM -0800, bruno desthuilliers wrote:
> > > (r'^app/(?P<object_id>\d+)/$', create_update.update_object,
> > > {'model': App}, 'app-edit'),
>
> > > Now, using {% url 'app-edit' object.pk %} in a form throws
> > > TemplateSyntaxError, mentioning "NoReverseMatch: Reverse for
> > > 'rc.'app-edit'' with arguments '(1,)' and keyword arguments '{}' not
> > > found."
>
> > The above url works with a named (aka 'keyword') param 'object_id', so
> > you do have to use the same scheme withing the url tag, ie:
>
> > {% url 'app-edit' object_id=object.pk %}
>
> Thanks for the tip. This results in TemplateSyntaxError with
> "NoReverseMatch: Reverse for 'rc.'app-edit'' with arguments '()' and
> keyword arguments '{'object_id': 1}' not found.". What am I doing
> wrongly?
>
> With kind regards,
> --
> Baurzhan Ismagulovhttp://www.kz-easy.com/

Should be {% url app-edit object_id=object.pk %} - ie drop the quotes
around app-edit.
--
DR.

Baurzhan Ismagulov

unread,
Dec 15, 2009, 11:53:47 AM12/15/09
to Django users
On Tue, Dec 15, 2009 at 08:00:54AM -0800, Daniel Roseman wrote:
> Should be {% url app-edit object_id=object.pk %} - ie drop the quotes
> around app-edit.

Yes, this worked. Thanks, Daniel and Bruno!

bruno desthuilliers

unread,
Dec 16, 2009, 3:53:13 AM12/16/09
to Django users
On 15 déc, 17:00, Daniel Roseman <dan...@roseman.org.uk> wrote:
>
> Should be {% url app-edit object_id=object.pk %} - ie drop the quotes
> around app-edit.

Duh :( I missed that one...
Reply all
Reply to author
Forward
0 new messages