【发布时间】:2017-07-06 18:03:56
【问题描述】:
views.py
class ProfileView(DetailView):
model = User
template_name ="profile/profile_view.html"
class ProfileEdit(UpdateView):
model = User
form_class = ProfileForm
template_name="profile/profile_new.html"
models.py
#.... models
def get_absolute_url(self):
return reverse('user:user_profile', kwargs={ "slug": self.slug })
urls.py
url(r'^(?P<slug>[\w.@+-]+)/edit/$', ProfileEdit.as_view(), name='profile_edit'),
url(r'^(?P<slug>[\w.@+-]+)/$', ProfileView.as_view(), name='user_profile'),
未找到带有参数“()”和关键字参数“{'slug': 'rahul'}' 的“user_profile”的反向操作。尝试了 0 个模式:[]
我不明白我得到了正确的 slug 值,但是将它传递给 url 模式的正确方法是什么?
【问题讨论】:
-
您的应用是否在包含这些网址的已安装应用设置中?
-
是的!详细视图和更新视图都可以正常工作..在更新视图中的发布请求之后我想重定向到详细视图
-
user命名空间肯定存在? (请包括相关的基本网址) -
url(r'^', include('user.urls', name='user')),