Python Django HttpResponseRedirect(反向('url'))返回NoReverseMatch错误

Python Django HttpResponseRedirect(反向('url'))返回NoReverseMatch错误,python,django,django-views,Python,Django,Django Views,我有这个标签 我想如果用户单击它,他/她应该重定向到此URL: 如何解决此问题?您使用mysite:user\u配置文件进行反向调用,但URL不在命名空间中。您应该只使用user_profile,或者为包含在调用中的URL设置名称空间 这里将更详细地解释名称空间 我不明白你的答案。我尝试返回HttpResponseRedirectreverse'user_profile',kwargs={'user_id':intuser.id,'user_name':user.name},但仍然得到相同的错误

我有这个标签

我想如果用户单击它,他/她应该重定向到此URL:

如何解决此问题?

您使用mysite:user\u配置文件进行反向调用,但URL不在命名空间中。您应该只使用user_profile,或者为包含在调用中的URL设置名称空间


这里将更详细地解释名称空间

我不明白你的答案。我尝试返回HttpResponseRedirectreverse'user_profile',kwargs={'user_id':intuser.id,'user_name':user.name},但仍然得到相同的错误。您能否显示模型的get_absolute_url方法以及您在模板中引用url的方式?您显示的链接是HTML,它可能是您生成的输出,但不是Python解释器正在处理的内容。您为什么要这样做,而不是通过a标记中自己的url直接将它们发送到视图?
url(r'^user/(?P<user_id>\d+)/(?P<user_name>[-\w]+)/$', views.user_profile, name='user_profile')
def profile(request, user_name):
    try:
        user = Users.objects.get(username = user_name)
    except Users.DoesNotExist:
        user = none
        if user is not None:
            return HttpResponseRedirect(reverse('mysite:user_profile', kwargs={'user_id': int(user.id), 'user_name':user.name}))

def user_profile(request, user_id, user_name):
    pass