开发者

django urlconf or .htaccess trouble

I am running my django project from subfolder of a website. Lets say the address where my project is meant to open from is.

http://example.com/myproject/

the myproject folder is root folder for my user account. In that folder i have fcgi script that starts my project. The .htaccess file in the folder contains this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.fcgi/$1 [QS开发者_运维问答A,L]

The trouble is, that at some cases, instead of redireting user to page like

http://example.com/myproject/social/someurl/

it redirects to

http://example.com/social/someurl/

which does not work. What i want to know is how to fix this problem.

Redirects in django-socialauth (github.com/uswaretech/Django-Socialauth), socialauth.views.py line 177 redirects without /myproject/, similar to the generic example above. I also use django cms2.0 in the project and it redirects user at admin auth to example.com/en/myproject/admin/, not example.com/myproject/en/admin. But that could be django cms's problem.

Is this kind of behaviour django problem and i should change it with urconf and add myproject to all urls, or should i do this with .htaccess? I found similar question, which, sadly, remains unanswered: How to write .htaccess if django project is in subfolder and subdomain?

Alan.


It's seems that django-cms-2.0 add the locale prefix to the url using the middleware level. Very well indeed.

But what's more interesting is that they prefix all of the url using resolve('pages-root')

So, you might be able to do this in the urls.py instead...

if not settings.DEBUG:
    urlpatterns += patterns('',
       url(r'^myproject/$', details, {'slug':''}, name='pages-root')
    )

Just make sure that you append the above urlpatterns before the cms.urls.


What if you try

RewriteRule ^(myproject/.*)$ mysite.fcgi/$1 [QSA,L]


Set the RewriteBase:

RewriteEngine On
RewriteBase /myproject/


In /urls_production.py

from django.conf.urls.defaults import *
urlpatterns = patterns('', 
    (r'^myproject/', include('urls')),
)

In /settings_production.py

from settings import *
ROOT_URLCONF = 'urls_production'

Make sure you set DJANGO_SETTINGS_MODULE to settings_production in the server environment.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜