django site framework bug, site name swaps back and forth each request

76 views
Skip to first unread message

Joe Estes

unread,
Apr 18, 2015, 10:20:56 PM4/18/15
to django-d...@googlegroups.com

I am using django's sites framework. I am calling the site name through a context processor like below. The problem is that every time the page loads, it switches between site1 and site2:

def site_info(request):

    Site.objects.clear_cache()# i tried with and without this
    site = get_current_site(request)
    site_detail = SiteDetail.objects.get(site_id=site.id)


    return {
            'site_domain': site.domain,
            'site_name': site.name,
            'site_short_name': site_detail.short_name,
            }

In my template I simply refer to the site name to do some logic and it switches back and forth between 2 of my sites on every request:

{% if site_name = 'Site 1' %}
                        <img src="{% static 'img/site1-logo.png' %}" alt="">
                    {% elif site_name = 'Site 2' %}
                        <img src="{% static 'img/site2-logo.png' %}" alt="">
                    {% endif %}

My httpd.conf looks like this:

<VirtualHost *:80>
    ServerName mysite1.com
    DocumentRoot /var/www/html/mysitedjango
    WSGIScriptAlias / /var/www/html/mysitedjango/mysite1/mysite1_wsgi.py
</VirtualHost>

<VirtualHost *:80>
    ServerName mysite2.com
    DocumentRoot /var/www/html/mysitedjango
    WSGIScriptAlias / /var/www/html/mysitedjango/mysite1/mysite2_wsgi.py
</VirtualHost>



Alias /static/ /var/www/html/mysitedjango/shared/static/

<Directory /var/www/html/mysitedjango/shared/static/>
Order deny,allow
Allow from all
</Directory>

WSGIPythonPath /var/www/html/mysitedjango

<Directory /var/www/html/mysitedjango>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

I would like to file this as a bug in the sites framework because the server name that is printed in the request never swaps, but always reflects the domain name the request came in on.

Please let me know if any further explanation is needed.



Florian Apolloner

unread,
Apr 19, 2015, 3:03:44 AM4/19/15
to django-d...@googlegroups.com
 Hi,

this is certainly a bug in your code or deployment via mod_wsgi (eg the two projects are in the same python process).

Cheers,
Florian

Collin Anderson

unread,
Apr 19, 2015, 8:01:40 AM4/19/15
to django-d...@googlegroups.com

Joe

unread,
Apr 19, 2015, 4:29:55 PM4/19/15
to django-d...@googlegroups.com
@Collin, this is not the case.  As you can see I have 2 different WSGI files.  The contents of them are:

#site1_wsgi.py
 

import os

os
.environ.setdefault("DJANGO_SETTINGS_MODULE", "site1_settings")
 

from django.core.wsgi import get_wsgi_application
 

application
= get_wsgi_application()




and 


#site2_wsgi.py


import os

os
.environ.setdefault("DJANGO_SETTINGS_MODULE", "site2_settings")


from django.core.wsgi import get_wsgi_application


application
= get_wsgi_application()

Joe

unread,
Apr 19, 2015, 4:32:47 PM4/19/15
to django-d...@googlegroups.com
@Florian What do you mean the projects are in the same python process?  

This is a standard implementation of the sites framework above, which leads me to believe there is a bug in django 1.7

Florian Apolloner

unread,
Apr 19, 2015, 5:13:03 PM4/19/15
to django-d...@googlegroups.com


On Sunday, April 19, 2015 at 10:32:47 PM UTC+2, Joe wrote:
@Florian What do you mean the projects are in the same python process?  

Let me phrase it differently, does it also happen if you run every project manually using runserver? If no, then this is a configuration bug, please see the mod_wsgi docs for details on what process groups and application groups are and how they interact with each other.

Cheers,
Florian

Collin Anderson

unread,
Apr 19, 2015, 6:41:13 PM4/19/15
to django-d...@googlegroups.com
Try it without setdefault or use daemon mode :)

The "standard" configuration has this exact problem, which there's a warning in the docs and why daemon mode is recommended. 
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/dd19d815-224e-4102-9656-e3f493878e2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Collin Anderson

unread,
Apr 19, 2015, 6:45:21 PM4/19/15
to django-d...@googlegroups.com
(Multiple config files doesn't mean multiple processes. Daemon mode is the only way to get a separate process per site.)

On Sunday, April 19, 2015, Joe <j...@buffernet.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages