views:

123

answers:

2

Did a few searches but couldn't find anything good about this problem.

I've got the following setup. / (index), /blog/ and /about/. The way I do want it to be displayed, running only one Django instance is blog.domain.com (for my blog app) and all the other urls to run under (www.)domain.com/.

I could surely hardcode the links, forcing this setup (basically the webserver will listen to blog.domain.com and do a forward as domain.com/blog/ but the user will still see blog.domain.com) but I want to be able to resolve my url-configs the proper way but still get them to point to domain.com or blog.domain.com depending on the url (app) being resolved.

Is there a good way of doing this? I was thinking of a custom templatetag to use instead of {% url my_resolve_name slug="test" as test %}.

A: 

There is no builtin support for it, but many people (including me) have done it in a hackish sort of way.

http://uswaretech.com/blog/2008/10/using-subdomains-with-django/
http://uswaretech.com/django-subdomains/

uswaretech
How will that help me to be able to resolve all my blog-app urls to blog.domain.com but all other resolves will go to domain.com? If I'm at blog.domain.com all url's will be resolved to blog.domain.com and not only the blog-app-related ones.
xintron
Ok if you are going to have only two subdomains, this isnt the optimal way. In this case I will have two different settings `settings_blog`, which hasonly the blog application, and Apache virtualhost points to a wsgi file which has `DJANGO_SETTINGS_MODULE` set to settings_blog. The other virtualhost responds to everything else on example.com and has a wsgi file which has `DJANGO_SETTINGS_MODULE` set to settings, which has all other apps.
uswaretech
That only works if I use Apache, which I don't. Running nginx and django as fastcgi (though might try uwsgi later on).
xintron
A: 

try this on nginx:

server { 
    listen 80;
    server_name www.example.com;

    if ($host ~* "^blog\.example\.com") {
        rewrite  ^(.*)$ /blog$1 permanent;
        break;
    }
}

this rewrites all requests to blog.example.com/some/params/ to www.example.com/blog/some/params

renton
I've got that working. The problem is to make django resolve urls to the right subdomain. Either blog. if it's the blog application or to www. if it's links other than links to the blog application.
xintron