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'),
反向'user_profile',参数'()'和关键字参数'{'slug':'rahul'}'找不到。尝试了0种模式:[]
我不明白我得到了正确的slug值但是将它传递给url模式的正确方法是什么?
答案 0 :(得分:1)
使用include
时,您需要指定namespace
,而不是name
url(r'^', include('user.urls', namespace='user'))