0

I would like to change the url that we are redirected after saving any change on Django admin page. The url defaults to 127.0.0.1:8000 because of the reverse proxy setting between nginx and gunicorn, and I would like to change it to my domain, e.g. mysite.com.

Referring to @Ber's question, I decided to override response_change() method in admin.py I created under the django app directory as below but it does not work due to lack of knowledge.

from django.contrib import admin

class ModelAdmin(admin.options.ModelAdmin):
    def response_change(self, *args, **kwargs):
        redirect_url = 'mysite.com'

        super(ModelAdmin, self).response_change(*args, **kwargs)

How may I improve this code so it can work properly?

Community
  • 1
  • 1
ronnefeldt
  • 2,083
  • 23
  • 24
  • I would suggest fixing the nginx config instead,because you will run into other issues later on as well, e.g. redirects outside admin, see: http://gunicorn-docs.readthedocs.org/en/latest/deploy.html – andrean Apr 24 '15 at 06:36

1 Answers1

0

The result never returned, you can try like this:

default = super(ModelAdmin, self).response_change(*args, **kwargs)
default.redirect_url = 'mysite.com'
return default
shellbye
  • 4,620
  • 4
  • 32
  • 44
  • Thanks, @shellbye. I amended the code to return as you advised, but the redirect url looks the same after saving changes on Django admin page. Maybe response_change() is not the one I am looking for? – ronnefeldt Apr 24 '15 at 11:07
  • I updated my answer and maybe [this](http://stackoverflow.com/questions/1339845/redirect-on-admin-save) question will help you too. – shellbye Apr 24 '15 at 14:03