📜 ⬆️ ⬇️

On the root directory

In spite of all my tricks and attempts to make the site on janga katalogo-independent, I nevertheless came across a rake buried in the jang itself.

Let me remind you that all the fuss is due to the fact that the customer (and me) the root directory of the site is not always the root directory of the domain. Those. The first page of the site is often located at site / dj , for various technical reasons. The most common one is that the customer has some PHP modules that are on the same server and are also needed.

The ambush at the same time lies in the fact that in templates and httpredirect it is necessary to specify the full paths to the pages. And if within the junga itself this path is still understandable (although I consider the need to indicate the full path to the page with httpredirect to be the full path to the page to be ugly), then the root directory may change. And then shovel all the code to fix it will be sad.
')
I found the following output: the variable ROOT = '' is written in settings.py and a small templatetag is written:

root.py:
from django.template import Library

register = Library ()

register .simple_tag
def root ():
"" "
Returns the string contained in the setting ROOT.
"" "
try:
import settings
except ImportError:
return ''
return settings.ROOT


and all Now in the templates after {% load root%} we write at the beginning of each path {% root%} and we get what we wanted. In viewax, respectively, use for the same purposes settings.ROOT

The trouble came from no waiting. It turned out that in the depths of the auth of Jhang there is a path '/ accounts / login' nailed with nails, to which requests are redirected if authorization is necessary. At the moment I see two ways out: either not to use standard decorators to check if the user is logged in (which is inconvenient), or to hack the jung itself. While I went the second way, but this is wrong.

I added a line to django / contrib / auth / __ init__.py
if hasattr (settings, 'LOGIN_URL'): LOGIN_URL = settings.LOGIN_URL


and added in settings.py
LOGIN_URL = '% s / login /'% ROOT

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


All Articles