pass link value in argument for view

35 views
Skip to first unread message

quentin ladrier

unread,
May 9, 2016, 9:05:20 AM5/9/16
to Django users
hello,

I generate in views different link. the value of link is a variable provide by search fonction.
this value change with search result.
so when I click to my link I wish my link value pass in argument for the new view.
I have test this kind of structure <a href= {% url 'my_app.views.my_view' myarg %}> {{ myarg}} </a> 
with urls like : url(r'^myapp/(?p<myarg>\*)$', views.my_view)
and views like: def my_view(request, myarg).
but when I attempt to generate my view some errors about arguments occur with 1 tried.

Can you help me with that or do you have any other way to obtain the same result ? 

thanks for your help,

regards,



C. Kirby

unread,
May 9, 2016, 11:03:56 AM5/9/16
to Django users
Please provide the specific error message you are seeing

quentin ladrier

unread,
May 11, 2016, 10:28:59 AM5/11/16
to Django users
sorry for the delay . I obtain this kind of error message:
NoReverseMatch at /my_views/my_arg/ . Reverse for 'xxx' with arguments '(my_arg,)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['my_views/(?P<my_arg>\d+)$']

Tom Evans

unread,
May 12, 2016, 5:27:21 AM5/12/16
to django...@googlegroups.com
On Wed, May 11, 2016 at 3:28 PM, quentin ladrier <kent17...@gmail.com> wrote:
> sorry for the delay . I obtain this kind of error message:
> NoReverseMatch at /my_views/my_arg/ . Reverse for 'xxx' with arguments
> '(my_arg,)' and keyword arguments '{}' not found. 1 pattern(s) tried:
> ['my_views/(?P<my_arg>\d+)$']

\d+ means 1 or more digits (0-9). 'my_arg' doesn't match that. Either
pass a number, or change the regular expression to match the content
of the argument you wish to pass.

Cheers

Tom

quentin ladrier

unread,
May 12, 2016, 5:32:20 AM5/12/16
to Django users
so I have test with an S+ or *  and finally I obtain same error message.

this my first django project

regards

quentin

C. Kirby

unread,
May 12, 2016, 11:06:56 AM5/12/16
to Django users
use \w+ to capture characters and digits. Also general django practice is to end all urls with a slash so:

url(r'^myapp/(?P<myarg>\w+)/$', views.my_view)
Reply all
Reply to author
Forward
0 new messages