0
我试图避免不得不以某种方式添加一个context_processor来将我的项目的基础url添加到我在所有模板中使用的每个url。Django在子目录中使用fcgi
我的Django项目是一个子目录下依偎(可以称之为富),并在我的模板了很多我的网址是否与此类似:
<a href='/somepath'>whatever</a>
这工作得很好,其在托管的项目一个域的根,但在这种情况下,因为我在子目录foo下,url实际上指向 www.example.com/somepath
有趣的是管理员网站正常工作。它的所有url都指向 foo/admin/...
我怀疑我没有搜索正确的术语来找到答案。
的.htaccess
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ foo.fcgi/$1 [L]
.fcgi
#!/usr/bin/python
import sys, os
# Current Path
cwd = os.path.join(os.path.dirname(os.path.abspath(__file__)))
# Activate current virtualenv
activate_this = os.path.join(cwd, 'bin', 'activate_this.py')
execfile(activate_this, dict(__file__ = activate_this))
# Add a custom Python path.
sys.path.insert(0, os.path.join(cwd, 'foo'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'foo.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
大多数网址我可以使用{%URL%}和FORCE_SCRIPT_NAME正确有工作,但对于网址的,我没有一个在urls.py中输入reverse(),我不知道是否应该在模板中使用FORCE_SCRIPT_NAME变量,还是有更好的方法?