我的用户配置文件更新视图(基于 class 的视图)returns a 404

My user profile update view (class based view) returns a 404

我有一个 UserProfile 模型,我想让人们根据需要更新它。

views.py

from django.views.generic.edit import CreateView, UpdateView

class UserProfileUpdateView(UpdateView):
    model = UserProfile
    form_class = UserProfileForm
    template_name = "preferences.html"
    success_url = "/profile/"

    def get_context_data(self, *args, **kwargs):
        context = super(UserProfileUpdateView, self).get_context_data(*args, **kwargs)
        return context

urls.py

from profiles import views
from profiles.views import UserProfileCreateView, UserProfileUpdateView

urlpatterns = [url(r'^profile/(?P<pk>\d+)$/edit', UserProfileUpdateView.as_view(), name='update_profile'),]

现在我的问题是,当我尝试转到 http://127.0.0.1:8000/profile/someusername/edit 时,我得到了 404。我不明白 url 模式中的 pk 到底发生了什么。我应该使用什么 url 模式来查看可以更新个人资料的页面?或者这里有什么问题?

您的正则表达式中间有一个 $,这没有任何意义,因为那是终止符。删除它。