django-sitetree icon indicating copy to clipboard operation
django-sitetree copied to clipboard

Handle mutliple urls.py

Open peterfication opened this issue 10 years ago • 5 comments

Hey there,

I'm using django-subdomains and django-sitetree in the same project. Therefore, I have 2 differenet urls.py. Eg. one for www.example.com (here is also admin) and one for subdomain.example.com. On both, I have included a sitetree, but different ones.

If I start the server, everything works fine. But if I change the sitetree in django admin, only the sitetree on the site with admin works fine and the urls are resolved. On the subdomain the sitetree shows up but the urls aren't resolved. If the server reloads, eg. due to changes in the code, the sitetree on the subdomain works again.

I tried to figure out how what happens on a reload, but I couldn't. Could you give me hint, what I can do to fix my problem?

Best wishes

peterfication avatar Nov 02 '13 08:11 peterfication

Finally, I figured out where the caching problem is. Somehow the cache isn't really cleared.

If I change in sitetree.cache_init

cache_ = cache.get('sitetrees')

to

cache_ = None

it works fine.

Do you have an idea, how to fix this Problem?

peterfication avatar Nov 02 '13 09:11 peterfication

Ok I was wrong. The caching works fine :)

But I figured out where the caching problem is. After saving in Admin, the sitetree gets initiated, but in the Admin. Therefore, the urls.py of subdomains aren't recognized.

I solved this issue by disabling the caching in the Admin.

peterfication avatar Nov 02 '13 10:11 peterfication

Hi,

Unfortunatelly I have no clue on how does your initial problem relate to the given solution. The problem, most probably, lays within multiple processes spawned not sharing cache data. What cache type do you use? https://docs.djangoproject.com/en/dev/topics/cache/

idlesign avatar Nov 03 '13 03:11 idlesign

I'm using the default cache ('BACKEND': 'django.core.cache.backends.locmem.LocMemCache',)

I think the problem lays somewhere in the Admin. After a server restart, if the first load of the sitetree is in the Admin (which is located under the main site) eg. for editing the sitetree the sitetreeapp looks for the urls.py of the main site to resolve the patterns. But there are none because they are all in the subdomains urls.py which is not loaded. If I then go to the subdomains site, the sitetree is already cached with unresolved urls. If the sitetree doesn't get cached in the Admin, it gets reloaded on the first load of the subdomains with the correct urls.py and therefore the urls are resolved.

My problem was, that I was changing a sitetree item of the subdomains sitetree in the Admin and then I was redirected to the overview of this sitetree in the Admin. After saving, the cache was cleared but because I was redirected to this overview, the sitetree gets cached immediately but with the wrong urls.py.

Therefore I disabled caching in the Admin.

peterfication avatar Nov 03 '13 07:11 peterfication

I see your point. I should take a closer look into django-subdomains before taking a decision on pull request. Thank you for the report!

idlesign avatar Nov 03 '13 07:11 idlesign