Q:

Django NoReverseMatch error on admin site

I get the following error on a redirect call when using my admin site to process an image:
NoReverseMatch at /admin/restapi/checkuserimage/1

Reverse for 'pendinguserimages' with arguments '()' and keyword arguments '{}'
not found. 0 pattern(s) tried: []

In urls.py I have:
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
...
]

And in admin.py:
class UserImageListPendingView(ListView):
    model = UserImage
    queryset = UserImage.objects.filter(status=ImageBase.PENDING)
    template_name = 'userimage_list_pending.html'
    context_object_name = 'userimage_list'
    paginate_by = 5
    @method_decorator(staff_member_required)
    def dispatch(self, *args, **kwargs):
        return super(UserImageListPendingView, self).dispatch(*args, **kwargs)

@staff_member_required
def userimage_check(request, pk):
    context = RequestContext(request)
    user_image = get_object_or_404(UserImage, pk=pk)
    if request.method == 'POST':
        proc_image(request, user_image, user_image.user, Count.USER_IMAGES)
        return HttpResponseRedirect(reverse_lazy('pendinguserimages'))
    else:
        context_dict = {
            'pk': pk,
            'username': user_image.user.username,
            'image_url': user_image.image.url
        }
        return render_to_response('userimage_check.html', context_dict, context)

def get_admin_urls(urls):
    def get_urls():
        return patterns('',
            url(r'^restapi/pendinguserimages/?$',
                 UserImageListPendingView.as_view(), name='pendinguserimages'),
            url(r'^restapi/checkuserimage/(?P<pk>[0-9]+)/?$',
                userimage_check, name='checkuserimage'),
        ) + urls
    return get_urls

admin.site.get_urls = get_admin_urls(admin.site.get_urls())

The error occurs on the reverse_lazy function.  Something's not right!

A:

Try including the admin namespace when you reverse the URL.
return HttpResponseRedirect(reverse('admin:pendinguserimages'))

You shouldn't have to use reverse_lazy inside a view function, reverse should work.

