passing arguments in HttpResponseRedirect(reverse())

1,719 views
Skip to first unread message

Guri

unread,
Feb 21, 2009, 6:37:11 PM2/21/09
to Django users
Hi,
I need help in solving two small problems.

1. A form submitted, after validation calls HttpResponseRedirect
(reverse('view.get_links',args=(request.POST['data'])))

In url pattern
(r'^links/(?P<tname>.*)/',get_links),

I am trying to send one more argument along with "request.POST
['data']" but it should not be part of pattern matching in URL.
I tried adding it in args tuple and same arg in my view and I get this
error:
AttributeError at /links/dsf/
'str' object has no attribute '_clone'

2. Another issue is I am trying to make a queryset using a loop
something like
for tag in tag_str:
qs = qs & Tags.objects.filter(tag_name__exact = tag)

return list_detail.object_list(request.....querset=qs,...)
Please tell me if this is somewhere near correct?

Thanks In Advance
Guri

Malcolm Tredinnick

unread,
Feb 22, 2009, 6:30:43 PM2/22/09
to django...@googlegroups.com
On Sat, 2009-02-21 at 15:37 -0800, Guri wrote:
> Hi,
> I need help in solving two small problems.
>
> 1. A form submitted, after validation calls HttpResponseRedirect
> (reverse('view.get_links',args=(request.POST['data'])))
>
> In url pattern
> (r'^links/(?P<tname>.*)/',get_links),
>
> I am trying to send one more argument along with "request.POST
> ['data']" but it should not be part of pattern matching in URL.
> I tried adding it in args tuple and same arg in my view and I get this
> error:
> AttributeError at /links/dsf/
> 'str' object has no attribute '_clone'

*How* did you try to add it? You show us the error message, but not what
you did to cause it. I don't understand what you are trying to do
(request.POST has nothing to do with URL parsing, so I'm not sure if
you're trying to do something impossible or if that's an unrelated
thing), but showing what you attempted would provide some clues.

>
> 2. Another issue is I am trying to make a queryset using a loop
> something like
> for tag in tag_str:
> qs = qs & Tags.objects.filter(tag_name__exact = tag)
>
> return list_detail.object_list(request.....querset=qs,...)
> Please tell me if this is somewhere near correct?

It depends upon what you're trying to do. Is it syntactically and
API-wise correct? Looks about right. Will it achieve what you're
wanting? Only you know that, since you haven't explained the problem
you're trying to solve.

Reverse-engineering that little code fragment, it will add constraints
to the queryset so that all returned results must have tags with names
matching each of the names you pass in. If that's the goal, then you've
achieved it.

Regards,
Malcolm


Guri

unread,
Feb 23, 2009, 11:38:12 AM2/23/09
to Django users
I apologize for not being clear first time. Its so idiot of me.
Here m trying to provide a search page having a text box input and a
radio button. User types one or more tags to search and a radio input
button decides to either search local user account data or all
database for links.

Also there is a view (get_links) which takes one tag as argument and
returns the result links from database and corresponding line in
urls.py is
(r'^links/(?P<tname>.*)/',get_links)

And the idiot side of me tried to pass two arguments the tag string
from search form and radio button input to this one get_links view
using HttpResponseRedirect(reverse....).

Now I had realized that a new view is required to handle inputs from
search form.

I apologize all and especially Malcolm for wasting their time. I'll
not repeat such things in future.

And thanks to Malcolm for second point that is exactly I m trying to
achieve in results.
Looping through the space separated tag string and querying database
for links common to all of them.

***********************************
1. The code fragment in views.py :
def
if request.method == 'POST':
form = searchForm(request.user,request.POST)
if form.is_valid():

return HttpResponseRedirect(reverse
('zen.views.get_links',args=(request.POST['search_data'])))
else:
form = searchForm(request.user)

2.
def get_links(request,tname = None,template_name =
"showlinks.html",searchit=None):
qs= UserTagLink.objects.filter
(tag_id__tag_name__exact=tname)

extra = { 'user' : request.user }
return list_detail.object_list(request,extra_context =
extra,queryset=qs,template_name = 'showlinks.html')

3. In urls.py
(r'^links/(?P<tname>.*)/',get_links)

Regards
Gurminder
> R everse-engineering that little code fragment, it will add constraints
Reply all
Reply to author
Forward
0 new messages