简体   繁体   English

Django使用CreateView添加Slug

[英]Django adding Slug with a CreateView

Is there a way to add a slug into the Django CreateView that I can use in my context for the page. 有没有一种方法可以将子弹添加到Django CreateView中,以便在页面上下文中使用。 for example I have tried this: 例如,我已经尝试过:

url(r'^registration/profile/(?P<slug>[\w\-\_]+)/?$', RegistrationView.as_view(),
                           name='registration_profile'),

view 视图

class RegistrationView(BaseCreateView):
    form_class = AppUserIntroducerCreateForm
    template_name = "registration/register.html"
    slug_url_kwarg = 'slug'


    def get_context_data(self, **kwargs):
        context = super(RegistrationView, self).get_context_data(**kwargs)
        context['slug'] = self.slug.slug
        return context

but still get AttributeError: 'RegistrationView' object has no attribute 'slug' 但仍然会出现AttributeError: 'RegistrationView' object has no attribute 'slug'

kwargs在字典中的kwargs提供。

context['slug'] = kwargs['slug']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM