Why does reverse () add a server path?

I have several instances of my project running on my server, for example:

http://0.0.0.0/one http://0.0.0.0/two 

I also have an activation view available through:

 http://0.0.0.0/one/activate/u/1/c/123 

When I do reverse () in this view from the django shell, the URL specified to me as:

 /activate/u/1/c/123 

Thus, it does not include the /one server path. However, when I use reverse () to find the path to the page for sending email elsewhere in the project, reverse () seems to return the full path to the server + path to the view, for example:

 /one/activate/u/1/c/123 

Does anyone know why this is happening?

+4
source share
1 answer

reverse() should include this server path, so you can just use it in the link, and it will work without having to change anything else in your code. But manage.py shell does not set the appropriate path prefix; this code happens in the wsgi / etc handler. This is a Django # 16734 bug (which I, incidentally, reported: p).

You can get around this by calling django.core.management.base.set_script_prefix manually, presumably in settings.py . For instance:

 # when running through wsgi, this will get overriden # but it needed for manage.py from django.core.urlresolvers import set_script_prefix set_script_prefix('/one/') 
+5
source

Source: https://habr.com/ru/post/1402784/


All Articles