Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的用户配置文件更新视图(基于类的视图)返回404_Python_Django_Django Class Based Views - Fatal编程技术网

Python 我的用户配置文件更新视图(基于类的视图)返回404

Python 我的用户配置文件更新视图(基于类的视图)返回404,python,django,django-class-based-views,Python,Django,Django Class Based Views,我有一个UserProfile模型,我想让人们更新,如果他们愿意的话 视图.py from django.views.generic.edit import CreateView, UpdateView class UserProfileUpdateView(UpdateView): model = UserProfile form_class = UserProfileForm template_name = "preferences.html" succes

我有一个UserProfile模型,我想让人们更新,如果他们愿意的话

视图.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
from profiles import views
from profiles.views import UserProfileCreateView, UserProfileUpdateView

urlpatterns = [url(r'^profile/(?P<pk>\d+)$/edit', UserProfileUpdateView.as_view(), name='update_profile'),]
url.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
from profiles import views
from profiles.views import UserProfileCreateView, UserProfileUpdateView

urlpatterns = [url(r'^profile/(?P<pk>\d+)$/edit', UserProfileUpdateView.as_view(), name='update_profile'),]
从配置文件导入视图
从profiles.views导入UserProfileCreateView,UserProfileUpdateView
urlpatterns=[url(r'^profile/(?P\d+)$/edit',UserProfileUpdateView.as_view(),name='update_profile'),]
现在我的问题是,当我试图去我得到一个404。我不太明白URL模式中的pk到底发生了什么。我应该使用什么url模式来查看可以更新配置文件的页面?还是这里出了什么问题


<>

> p>在正则表达式的中间有一个<代码> $/COD>,这是没有意义的,因为这是终止符。删除它。

此外,您的URL模式需要一个id,并且看起来您正在发送一个用户名,但这不起作用。更改正则表达式模式以接受字符,或者更好的是,将其移动到正则表达式的末尾:
^profile/(?P\d+)/edit$
非常感谢,它是正则表达式和@karthikr所说内容的组合。