kwargs are not available in the get_context_method of generic CreateView, why?

23 views
Skip to first unread message

Sabine Maennel

unread,
Sep 25, 2014, 3:41:39 PM9/25/14
to django...@googlegroups.com
Please help:

I am using Django's Class based Generic CreateView:

url:

urls.py
urlpatterns = patterns("",
    url(r'^(?P<slug>[a-z0-9_-]{3,50})/(?P<offer_id>\d+)/$', OrderCreateView.as_view(), name='form'),
)

There are clearly kwargs, that I use. My context processor picks them up and they can be used in my template, but
in the view, there is only one kwarg, which is the form: My print statement below has the following output:

{'form': <django.forms.models.UserAccountForm object at 0x111725e50>}

.view.py:
class OrderCreateView(CreateView):

    template_name = 'order/order_register.html'
    model = UserAccount
    fields =('about',)

    def get_context_data(self, *args, **kwargs):
        print kwargs
        context = super(OrderCreateView, self).get_context_data(*args, **kwargs)
        courseevent = CourseEvent.objects.get(slug=kwargs['slug'])

How can I get related objects into my context with CreateView or what should I use instead. Any suggestions would be most welcome, 
since I somehow struggle to understand this.

      with kind regards and thanks in advance
           Sabine

Collin Anderson

unread,
Sep 25, 2014, 4:48:45 PM9/25/14
to django...@googlegroups.com
print self.kwargs

Sabine Maennel

unread,
Sep 25, 2014, 5:54:46 PM9/25/14
to django...@googlegroups.com
Danke Collins, das wars!

Am Donnerstag, 25. September 2014 22:48:45 UTC+2 schrieb Collin Anderson:
print self.kwargs
Reply all
Reply to author
Forward
0 new messages