{% url admin:index %} 生成错误的网址
我的 django 站点在 Apache 的配置中提供以下内容:
WSGIScriptAlias /studio /django/studio/bin/django.wsgi
我的 urls.py 看起来像:
urlpatterns += patterns(
'django.contrib',
(r'^admin/', include(admin.site.urls)),
(r'^accounts/login/$', 'auth.views.login'),
(r'^accounts/logout/$', 'auth.views.logout'),
)
...但是:
[<a href="{% url admin:index %}">admin</a>]
...生成到 /admin 而不是 /studio/admin 的链接。 奇怪的是,管理界面本身内的 URL 没有问题。
我正在使用:
Python 2.5.2-3
Django 1.1.1
mod_wsgi 2.5-1~lenny1
apache2 2.2.9-10+lenny6
任何人都可以告诉我我做错了什么吗?
干杯,
克里斯
My django site is served up with the following in Apache's config:
WSGIScriptAlias /studio /django/studio/bin/django.wsgi
My urls.py looks like:
urlpatterns += patterns(
'django.contrib',
(r'^admin/', include(admin.site.urls)),
(r'^accounts/login/
...and yet:
[<a href="{% url admin:index %}">admin</a>]
...generates a link to /admin rather than /studio/admin.
Bizarrely, the urls within the admin interface itself are fine.
I'm using:
Python 2.5.2-3
Django 1.1.1
mod_wsgi 2.5-1~lenny1
apache2 2.2.9-10+lenny6
Can anyone tell me what I'm doing wrong?
cheers,
Chris
, 'auth.views.login'),
(r'^accounts/logout/
...and yet:
...generates a link to /admin rather than /studio/admin.
Bizarrely, the urls within the admin interface itself are fine.
I'm using:
Can anyone tell me what I'm doing wrong?
cheers,
Chris
, 'auth.views.logout'),
)
...and yet:
...generates a link to /admin rather than /studio/admin.
Bizarrely, the urls within the admin interface itself are fine.
I'm using:
Can anyone tell me what I'm doing wrong?
cheers,
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 Django 中的一个错误,请参阅:
http://code.djangoproject.com/ticket/12464
问题是,由于我需要在虚拟主机的其他地方进行重写,因此 Apache 的重写引擎处于打开状态,因此设置了 SCRIPT_URL 环境变量。但是,当通过 Apache 向 /project 发出请求时,PATH_INFO 为空,这会导致 SCRIPT_NAME 被错误地设置为空字符串。
在修复此错误之前,将以下 RewriteRule 插入 Apache 配置中将通过确保 PATH_INFO 永远不为空来安全地解决该问题。
This is a bug in Django, see:
http://code.djangoproject.com/ticket/12464
The problem is that because Apache's rewrite engine is on as a result of rewriting I need to do elsewhere in the virtual host, the SCRIPT_URL environment variable is set. But, when a request is made to /project through Apache, PATH_INFO is empty, which results in SCRIPT_NAME being incorrectly set as an empty string.
Until this bug is fixed, inserting the following RewriteRule into the Apache configuration will safely work around the problem by ensuring that PATH_INFO is never empty.
您的 Django 实例对 URL 的
/studio
部分一无所知,因为它是在 WSGI 中处理的。您必须在模板中手动添加它,或者更好的是在 urls.py:in settings.py:
in urls.py: 中
添加它,然后您的 url 反转将按预期工作。您的管理链接有效,因为一旦您进入管理界面,所有链接都是相对的。
Your Django instance knows nothing about the
/studio
part of the URL as it is handled in WSGI. You have to manually prepend it either in templates or, better, in urls.py:in settings.py:
in urls.py:
Then your url reversing will work as expected. You admin links work because once you are in the admin interface all links are relative.