开发者

Hosting Django Project at /test @login_required redirects to /accounts instead of /test/accounts

I'm moving a project to new hosting and would like to set it up such that it sits at mysite.com/test/ (this is under mod_wsgi on an Apache server). This开发者_开发百科 seems to do alright for the application itself, but when I use @login_required to enforce authentication Django redirects to mysite.com/accounts/login instead of mysite.com/test/accounts/login as I would like. I also have a mysite.com/prod that I want to do this same thing on so I don't want to hard code this anywhere in settings... it should figure out where the root of its URL is and act accordingly.

How do I set it up so that Django automagically redirects to what Apache considers that application's web root?


You need to set LOGIN_URL and LOGOUT_URL to full URL path in Django settings file. See:

http://docs.djangoproject.com/en/1.3/ref/settings/#login-url

Django doesn't automatically insert the mount point at the start of those as so have to be fully qualified.


The same problem can be solved in a more generic way for all project URLs. You could checkout an alternative solution at Running a Django site on my local machine, am I redirecting my URLs properly? for an environment based ROOT URL support.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜