1

次のような URL があります。

url(r'^(?P<user_id>\d+)/profile/$', views.ProfileView.as_view(), name='profile'),

ユーザーがクリックすると、フォームの更新が行われ、を使用Update Profileして同じプロファイル URL にリダイレクトされます。messagemessaging framework

# views

# Use the message framework to pass the message profile successfully updated
messages.success(request, 'Profile details updated.')

# Redirect to the same view with the profile updated successfully message
return HttpResponseRedirect(reverse('profile', args=(request.user.id,)))

しかし、私はこのエラーが発生します:

NoReverseMatch at /5/profile/

Reverse for 'profile' with arguments '(5L,)' and keyword arguments '{}' not found.

どうしたの?

4

1 に答える 1

3

これは、Python 2.xx の仕組みによるものです。

データベース行から取得されるすべての整数には、接尾辞としてLor l(t は一般的に大文字L) が付きます。

すばやく汚れた方法の 1 つは、次のとおりです。

return HttpResponseRedirect(reverse('profile', args=(int(long(request.user.id)),)))
于 2013-09-30T06:44:27.837 に答える