The situation is:
I have Apache with mod_python on windows xp and my django project is not in the document root.
The Django project location is defined with the tag. The django.root ist also defined there.
All the urls work fine in the built-in server but unfortunately not in Apache. In some urls, especially the ones not pointing to the admin do not work. The django.root part gets cut off.
How can I avoid this ?
情况是:我在Windows XP上安装了带有mod_python的Apache,而我的django项目不在文档根目录中。 Django项目位置使用标记定义。 django.root也在那里定义。所有的url在内置服务器上运行良好,但遗憾的是不在Apache中。在某些网址中,特别是那些没有指向管理员的网址不起作用。 django.root部分被切断了。我怎么能避免这个?
One solution could be to set the django-project into Apache's document-root. Are there other solutions?
一种解决方案可能是将django项目设置为Apache的文档根。还有其他解决方案吗?
1 个解决方案
#1
Django will use the django.root part correctly if you compose links in the template files with {% url %} tags and by calling reverse() in your HTTPResponseRedirects() calls.
如果您使用{%url%}标记在模板文件中组合链接并在HTTPResponseRedirects()调用中调用reverse(),Django将正确使用django.root部分。
Its value is stored in HttpRequest - request.META['SCRIPT_NAME'] and you can use it also in templates with:
它的值存储在HttpRequest - request.META ['SCRIPT_NAME']中,你也可以在模板中使用它:
{% if user.is_staff %}
<li>
<a href="{{ request.META.SCRIPT_NAME }}/admin">Administration</a>
</li>
{% endif %}
#1
Django will use the django.root part correctly if you compose links in the template files with {% url %} tags and by calling reverse() in your HTTPResponseRedirects() calls.
如果您使用{%url%}标记在模板文件中组合链接并在HTTPResponseRedirects()调用中调用reverse(),Django将正确使用django.root部分。
Its value is stored in HttpRequest - request.META['SCRIPT_NAME'] and you can use it also in templates with:
它的值存储在HttpRequest - request.META ['SCRIPT_NAME']中,你也可以在模板中使用它:
{% if user.is_staff %}
<li>
<a href="{{ request.META.SCRIPT_NAME }}/admin">Administration</a>
</li>
{% endif %}