[Fixed]-Django Apache Subdomains

1👍

Your both url points to same root(/), so try as follows

in domain2_urls.py

from django.conf.urls import patterns, include, url

urlpatterns = patterns('',
    url(r'^domain2/$', 'domain2.views.domain2', name='domain2'),
)

0👍

I think you need change architecture of app. Catch domain info on view level.
For example:

from django.views.generic import View, TemplateView


class DomainMixin(View):
    def get_template_names(self):
        return ['{domain}/{template_name}'.format(domain=self.current_domain, template_name=self.template_name)]

    def dispatch(self, request, *args, **kwargs):
        self.current_domain = request.META['HTTP_HOST']
        return super(DomainMixin, self).dispatch(request, *args, **kwargs)

class IndexView(DomainMixin, TemplateView):
    template_name = 'my_app/index_view.html'

    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)

        ### domain specific logic ###
        if self.current_domain == '':
            pass

        return context

0👍

Django sites framework is created to deal with multiple sites sharing one database and maybe some other things, it wasn’t created to deal with one site spreaded across multiple domains.

To deal with it properly, i suggest django-subdomains package. It is created to deal with that exact case. It contains 4 main things: simple middleware that will detect your subdomain, middleware that inherits from previous and additionally can swap ROOT_URLCONF based on subdomain, new reverse function that will take subdomain keyword argument and do lookup for url in proper urlpatterns and new {% url %} template tag that will use new reverse function.

Leave a comment