Expected view to be called with a URL keyword argument named “pk”
View functions are called with the request and the arguments from the URL. So pass them: response = view(request, pk=1)
View functions are called with the request and the arguments from the URL. So pass them: response = view(request, pk=1)
Ajax will not redirect pages! What you get from a redirect is the html code from the new page inside the data object on the POST response. If you know where to redirect the user if whatever action fails, you can simply do something like this: On the server, In case you have an error … Read more
How about overriding form_valid which does the form saving? Save it yourself, do whatever you want to it, then do the redirect. class PlaceFormView(CreateView): form_class = PlaceForm @method_decorator(login_required) def dispatch(self, *args, **kwargs): return super(PlaceFormView, self).dispatch(*args, **kwargs) def form_valid(self, form): obj = form.save(commit=False) obj.created_by = self.request.user obj.save() return http.HttpResponseRedirect(self.get_success_url())
In your example, overriding queryset and get_queryset have the same effect. I would slightly favour setting queryset because it’s less verbose. When you set queryset, the queryset is created only once, when you start your server. On the other hand, the get_queryset method is called for every request. That means that get_queryset is useful if … Read more
If your urlconf looks something like this: url(r’^(?P<slug>[a-zA-Z0-9-]+)/$’, MyView.as_view(), name=”my_named_view”) then the slug will be available inside your view functions (such as ‘get_queryset’) like this: self.kwargs[‘slug’]