使用URL前缀运行Django站点 [英] Running Django site with a URL prefix
问题描述
我正在尝试将Django网站放在一个子路径中,如www.example.com/mysite/,但是我无法让它工作100%。
I'm trying to put my Django site in a subpath, say www.example.com/mysite/ but I can't get it to work 100%.
我阅读了关于 Django Apache重定向问题的答案,建议您更改管理员中的网站www.example.com到www.example.com/mysite/,这正是我想要做的,它几乎可以工作。主要urls.py中的所有url正确地被重定向,但是当使用模板中的链接时,include中的所有内容都会丢弃mysite指令(一个例子是 {%url journal_index%}
哪个更改后应该去www.example.com/mysite/journal,但是去www.example.com/journal /).
I read up on the answer Django Apache Redirect Problem , where it is suggested to just change the site in the admin from www.example.com to www.example.com/mysite/, which is exactly what I want to do and it almost works. All urls in the main urls.py gets redirected properly, but everything in the includes drop the "mysite" directive when using the links in the templates (one example is {% url journal_index %}
which after the change should go to www.example.com/mysite/journal but goes go www.example.com/journal/).
希望这样
Cheers!
推荐答案
尝试添加FORCE_SCRIPT_NAME设置:
Try adding the FORCE_SCRIPT_NAME setting:
FORCE_SCRIPT_NAME ='/ mysite'
FORCE_SCRIPT_NAME = '/mysite'
这篇关于使用URL前缀运行Django站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!