On Feb 25, 11:22 pm, Timothy Kinney <[email protected]> wrote:
> 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<samurai_id>.*)/add_item/$'
> r'^admin/myapp/samurai/(?P<samurai_id>.*)/$
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<album_id>[0-9]+)/$",
views.album_details,
name="album_details"
),
url(r"albums/(?P<album_id>[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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.