pass link value in argument for view

閲覧: 35 回
最初の未読メッセージにスキップ

quentin ladrier

未読、
2016/05/09 9:05:202016/05/09
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

未読、
2016/05/09 11:03:562016/05/09
To: Django users
Please provide the specific error message you are seeing

quentin ladrier

未読、
2016/05/11 10:28:592016/05/11
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

未読、
2016/05/12 5:27:212016/05/12
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

未読、
2016/05/12 5:32:202016/05/12
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

未読、
2016/05/12 11:06:562016/05/12
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)
全員に返信
投稿者に返信
転送
新着メール 0 件