Question

I have been trying to use "UpdateView" in django generic views. What I am trying to achieve is to return to the same "UpdateView" page. My codes are as follows:
My urls

#urls.py    
urlpatterns = patterns(
    '',
    url(r'^code/(?P<pk>\d+)/update/', CodeUpdate.as_view(model=Code, template_name='code_update.html'),name='update',),
    )

my views

#views.py
class CodeUpdate(UpdateView):
    def get_success_url(self):
        pass

After clicking the update button the I expected the destination to be

/code/18/update/

however it turns out to be

/code/18/update/None

How do I remove "None" at the end? Thanks.

Now if I do this:

#views.py
class CodeUpdate(UpdateView):
    def get_success_url(self):
        return reverse('update')

I will get this error.

Reverse for 'update' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'/code/(?P\d+)/update/']

How can I pass the 'pk' value as the argument in the reverse function.

Thanks.

Was it helpful?

Solution

Once update is successful, it will redirect to url returned by get_success_url(). As you are not returning anything in that function, you are redirected to .../update/None.

Either return appropriate url from that method or remove that method for default behavior.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top