You're better off not using the HTML rewriting features of your reverse proxy. Instead configure Django to use the reverse proxied url prefix for all it's URLs.
On December 29, 2018 9:03:39 AM CST, Zhe Li <[email protected]> wrote: >Hi, > >I am having issues with django installed on a server reversed proxied >to >the main website. Most of the sites work just fine except a very small >detail in the admin site, change form page. > >Django is running on server A, served at / on port 12345. Server B >which is >the main web server and has a domain www.example.com, and serves >content >(reverse proxies) from server A under /app/myapp. > >i.e. *http://A:12345/admin/* translates to >*https://www.example.com/app/myapp/admin*. > >Everything is fine except when I try to modify a foreign key value from >the >model that it is referenced. You know, if I modify fields of model A in >the >django admin site, I can click on these buttons to change a foreign key > >model B. > ><about:invalid#zClosurez>[image: Screen Shot 2018-12-29 at 9.45.42 >AM.png] ><about:invalid#zClosurez> > > > > > >The problem is that the links are not properly translated on server B. >The >"add" button is fine, but the "change" and the "delete" buttons are >not. >For example, the correct "change" button should point to >*https://www.example.com/app/myapp/admin/main/modelb/1/change/?_to_field=id&_popup=1*, > >but it actually points to >*https://www.example.com/admin/main/modelb/1/change/?_to_field=id&_popup=1*, > >which does not exist. The problem is that the relative URL is stored in >the >"data-href-template" attribute of the <a> tag, like this > >*<a class="related-widget-wrapper-link change-related" >> id="change_id_modelb" >> >data-href-template="/admin/main/modelb/__fk__/change/?_to_field=id&_popup=1" > >> title="Change selected modelb">* >> > >which is parsed by static/admin/js/admin/RelatedObjectLookups.js, which > >adds a "real" href attribute via JS, giving > >*<a class="related-widget-wrapper-link change-related" >> id="change_id_system" >> >data-href-template="/admin/main/modelb/__fk__/change/?_to_field=id&_popup=1" > >> title="Change selected modelb" >> href="/admin/main/modelb/1/change/?_to_field=id&_popup=1"><img >> src="/app/myapp/static/admin/img/icon-changelink.svg" >alt="Change"></a>* > > >The reverse proxy program, however, only translates whatever is in the >HTML ><a href="" />, and does nothing about this customized data field. > >This is not necessarily a bug, as it only happens in special cases like > >mine. I am not sure what to do -- I can modify this >RelatedObjectLookups.js >and just add '/app/myapp' in front of every link it produces, which >should >work and fix this problem at this point. However, a more complete >solution >would be to overhaul this lookup js and put a real link there, which is > >quite some work to do. Should I write a new ticket to Django Project, >or do >you have better suggestions? > >Thank you > >-- >You received this message because you are subscribed to the Google >Groups "Django users" group. >To unsubscribe from this group and stop receiving emails from it, send >an email to [email protected]. >To post to this group, send email to [email protected]. >Visit this group at https://groups.google.com/group/django-users. >To view this discussion on the web visit >https://groups.google.com/d/msgid/django-users/cf876c89-c3e7-414e-8290-1e050f80f7b7%40googlegroups.com. >For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/758772A2-552D-4B90-8D8D-B3F94DCF8EA9%40fattuba.com. For more options, visit https://groups.google.com/d/optout.

