Django Test Client and Subdomains

I'm trying to figure out how to make the Django test client play nice with my app that puts each user on it's own subdomain. ie each account has account1.myapp.com, account2.myapp.com.

A user could be members of multiple subdomains (similar basecamp's model) so i handle which subdomain the request is being issued against in middleware.

As I'm writing my unit tests, I realized that all requests are issued to "http://testserver" which my middleware then redirects and the subsequent 302 is not followed as it's determined to be an external request.

Anyone aware of a way to enable this with the test client? I'm currently hacking a bit in django to enable it.


in your tests, when using the client, add the HTTP_HOST parameter:

response = c.post(reverse('my-url'), data={}, HTTP_HOST='account1.myapp.com')

on your middleware now you should see the host changed!

链接地址: http://www.djcxy.com/p/33730.html

上一篇: MVC授权问题/重复登录请求

下一篇: Django测试客户端和子域