使用我的管理网站处理图片时,我在重定向调用时收到以下错误:
NoReverseMatch at /admin/restapi/checkuserimage/1
Reverse for 'pendinguserimages' with arguments '()' and keyword arguments '{}'
not found. 0 pattern(s) tried: []
在urls.py中我有:
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
...
]
在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())
reverse_lazy函数发生错误。有些事情不对!
答案 0 :(得分:1)
在撤消网址时尝试包含return HttpResponseRedirect(reverse('admin:pendinguserimages'))
命名空间。
reverse_lazy
您不应该在视图函数中使用reverse
, JButton[][] buttons = new JButton[20][20];
public void mines(){
ArrayList<Integer> x = new ArrayList<>();
ArrayList<Integer> y = new ArrayList<>();
for(int a=0;a<20;a++){
x.add(a);
y.add(a);
}
for(int i=0;i<30;i++){
int random_x = x.get(new Random().nextInt(x.size()));
int random_y = y.get(new Random().nextInt(y.size()));
x.remove(random_x);
y.remove(random_y);
buttons[random_x][random_y].setText("X");
}
}
应该有效。