Redirecting to a different view after posting a form
www.financecollection.blogspot.com www.financecollection.blogspot.com www.financecollection.blogspot.com www.financecollection.blogspot.com www.financecollection.blogspot.com www.financecollection.blogspot.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Redirecting to a different view after posting a form
On Feb 25, 11:22 pm, Timothy Kinneywrote: > I have taken a, perhaps, unorthodox tact for my admin views. I use > myproject/urls.py to grab the url and redirect to > myapp.admin_views.samurai_detail > > urls.py catches url patterns such as: > r'^admin/myapp/samurai/(?P.*)/add_item/$' > r'^admin/myapp/samurai/(?P.*)/$ These are the patterns, but not the full url definitions. Mine looks like: url(r"albums/create/$", views.album_edit, name="album_create" ), url(r"albums/(?P[0-9]+)/$", views.album_details, name="album_details" ), url(r"albums/(?P[0-9]+)/edit/$", views.album_edit, name="album_edit" ), In views, you'll have: def album_details(request, album_id): # code here def album_edit(request, album_id=None): # code here With this, I can call reverse with the url name appropriate kwargs: # url displaying album n°33 details: reverse('album_details', kwargs={'album_id':33}) # url for editing album n°42: reverse('album_edit', kwargs={'album_id':33}) # url for creating a new album: reverse('album_create') Then it's just a matter of passing the url to HttpResponseRedirect. > The HttpResponseRedirect is supposed to go from > admin_views.add_item_to_samurai (after a successful request.POST) to > admin_views.samurai_detail > > How would I craft the reverse() for that? cf above. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Redirecting to a different view after posting a form
I have taken a, perhaps, unorthodox tact for my admin views. I use myproject/urls.py to grab the url and redirect to myapp.admin_views.samurai_detail urls.py catches url patterns such as: r'^admin/myapp/samurai/(?P.*)/add_item/$' r'^admin/myapp/samurai/(?P.*)/$ I am keeping all of my admin_views in admin_views.py although I keep my ModelAdmin classes in admin.py, so I sort of have two admin files. The HttpResponseRedirect is supposed to go from admin_views.add_item_to_samurai (after a successful request.POST) to admin_views.samurai_detail How would I craft the reverse() for that? Note that if I do just do reverse('add_item_to_samurai') or however I try to pass in the samurai_id keyword, I get the same error (noted in top post). -TIm On Thu, Feb 25, 2010 at 4:14 PM, Karen Traceywrote: > On Thu, Feb 25, 2010 at 4:25 PM, bruno desthuilliers < > bruno.desthuilli...@gmail.com> wrote: > >> On 25 fév, 20:49, Timothy Kinney wrote: >> > I think I'll just >> > stick with urls. >> >> Mmmm... Fine for you if it works, but as far as I'm concerned I don't >> like it. I do use HttpResponseRedirect, but I pass in the result of a >> call to reverse(), always using named urls. OTHO, I don't know if >> admin urls are named. >> >> > They are, and reversable, as of 1.1: > http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#admin-reverse-urls > > I'm a little unclear on what's being done here to override admin views with > views provided by the app, though, so I'm not sure that's relevant for the > original question. Looking back at the original question I'd expect a view > named samurai_detail to take an argument that specifies what samurai to show > details for, yet the call to reverse specified no arguments. That could be > the cause of the revere() failure. Without specifics of the actual url > patterns being used, though, it's hard to ay for ure. > > Karen, using laptop with a barely functioning s key and tired of fixing the > tupid typo that reult. Sorry about that. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Redirecting to a different view after posting a form
On Thu, Feb 25, 2010 at 4:25 PM, bruno desthuilliers < bruno.desthuilli...@gmail.com> wrote: > On 25 fév, 20:49, Timothy Kinneywrote: > > I think I'll just > > stick with urls. > > Mmmm... Fine for you if it works, but as far as I'm concerned I don't > like it. I do use HttpResponseRedirect, but I pass in the result of a > call to reverse(), always using named urls. OTHO, I don't know if > admin urls are named. > > They are, and reversable, as of 1.1: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#admin-reverse-urls I'm a little unclear on what's being done here to override admin views with views provided by the app, though, so I'm not sure that's relevant for the original question. Looking back at the original question I'd expect a view named samurai_detail to take an argument that specifies what samurai to show details for, yet the call to reverse specified no arguments. That could be the cause of the revere() failure. Without specifics of the actual url patterns being used, though, it's hard to ay for ure. Karen, using laptop with a barely functioning s key and tired of fixing the tupid typo that reult. Sorry about that. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Redirecting to a different view after posting a form
On 25 fév, 20:49, Timothy Kinneywrote: > Thanks for the reply, Bruno. For some reason, that still doesn't work for > me. I can't figure out how to get reverse to work at all. But I took your > advice about HttpResponseRedirect and this worked fine: > > return HttpResponseRedirect('../') > > I was always trying to put views in HttpResponseRedirect. views names or views functions ? IIRC, reverse() takes both. > I think I'll just > stick with urls. Mmmm... Fine for you if it works, but as far as I'm concerned I don't like it. I do use HttpResponseRedirect, but I pass in the result of a call to reverse(), always using named urls. OTHO, I don't know if admin urls are named. What you could do is try to find out the correct args for reverse - you can check this out in the shell. My 2 cents. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Redirecting to a different view after posting a form
Thanks for the reply, Bruno. For some reason, that still doesn't work for me. I can't figure out how to get reverse to work at all. But I took your advice about HttpResponseRedirect and this worked fine: return HttpResponseRedirect('../') Since my path structure is: myProject/myApp/samurai/samurai_id/add_item All I need to do is back up one. I was always trying to put views in HttpResponseRedirect. I think I'll just stick with urls. -Tim On Thu, Feb 25, 2010 at 3:51 AM, bruno desthuilliers < bruno.desthuilli...@gmail.com> wrote: > On Feb 25, 1:15 am, Timothy Kinneywrote: > > I have two views: > > samurai_detail > > add_item_to_samurai > > > > There is a button in samurai_detail that links to add_item_to_samurai. > > The templates are the same except that add_item_to_samurai includes a > > form to add an item. > > > > After posting the form, I want to redirect back to samurai_detail (the > > page without the form that shows the items). > > > > As in the Django documentation, I thought I could do this with a > > redirect, like so: > > return redirect('samurai_detail') > > > > But this returns: Reverse for 'samurai_detail' with arguments '()' and > > keyword arguments '{}' not found. > > I personnaly still stick to using an HttpResponseRedirect with an > explicit call to reverse - mostly because I failed to spot this new > shortcut FWIW !-) > > > This is a little bit cryptic. I think it says it can't find my view. > > What it says is that it fails to find any url definition that would > call the samurai_detail view _without any argument_. > > > Both views are contained in myproject.myapp.admin_views.py > > > > Am I using reverse() incorrectly? How can I redirect to the > > samurai_detail view? > > What's the signature of your samurai_detail view ? > > Ok, assuming it's defined as > > def samurai_detail(request, samurai_id): > # code > > you could try either: > > return redirect('samurai_detail', samurai.id) > > or > > return redirect('samurai_detail', samurai_id=samurai.id) > > My 2 cents... > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Redirecting to a different view after posting a form
On Feb 25, 1:15 am, Timothy Kinneywrote: > I have two views: > samurai_detail > add_item_to_samurai > > There is a button in samurai_detail that links to add_item_to_samurai. > The templates are the same except that add_item_to_samurai includes a > form to add an item. > > After posting the form, I want to redirect back to samurai_detail (the > page without the form that shows the items). > > As in the Django documentation, I thought I could do this with a > redirect, like so: > return redirect('samurai_detail') > > But this returns: Reverse for 'samurai_detail' with arguments '()' and > keyword arguments '{}' not found. I personnaly still stick to using an HttpResponseRedirect with an explicit call to reverse - mostly because I failed to spot this new shortcut FWIW !-) > This is a little bit cryptic. I think it says it can't find my view. What it says is that it fails to find any url definition that would call the samurai_detail view _without any argument_. > Both views are contained in myproject.myapp.admin_views.py > > Am I using reverse() incorrectly? How can I redirect to the > samurai_detail view? What's the signature of your samurai_detail view ? Ok, assuming it's defined as def samurai_detail(request, samurai_id): # code you could try either: return redirect('samurai_detail', samurai.id) or return redirect('samurai_detail', samurai_id=samurai.id) My 2 cents... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Redirecting to a different view after posting a form
I should have mentioned explicitly that these are admin views, not standard user views. I catch the url patterns for them in myproject/ urls.py. Maybe this changes how reverse must be used? -Tim On Feb 24, 6:15 pm, Timothy Kinneywrote: > I have two views: > samurai_detail > add_item_to_samurai > > There is a button in samurai_detail that links to add_item_to_samurai. > The templates are the same except that add_item_to_samurai includes a > form to add an item. > > After posting the form, I want to redirect back to samurai_detail (the > page without the form that shows the items). > > As in the Django documentation, I thought I could do this with a > redirect, like so: > return redirect('samurai_detail') > > But this returns: Reverse for 'samurai_detail' with arguments '()' and > keyword arguments '{}' not found. > > This is a little bit cryptic. I think it says it can't find my view. > Both views are contained in myproject.myapp.admin_views.py > > Am I using reverse() incorrectly? How can I redirect to the > samurai_detail view? > > -Tim -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Redirecting to a different view after posting a form
I have two views: samurai_detail add_item_to_samurai There is a button in samurai_detail that links to add_item_to_samurai. The templates are the same except that add_item_to_samurai includes a form to add an item. After posting the form, I want to redirect back to samurai_detail (the page without the form that shows the items). As in the Django documentation, I thought I could do this with a redirect, like so: return redirect('samurai_detail') But this returns: Reverse for 'samurai_detail' with arguments '()' and keyword arguments '{}' not found. This is a little bit cryptic. I think it says it can't find my view. Both views are contained in myproject.myapp.admin_views.py Am I using reverse() incorrectly? How can I redirect to the samurai_detail view? -Tim -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.