【问题标题】:Django URLs repeat when using runfcgi使用 runfcgi 时 Django URL 重复
【发布时间】:2014-03-23 08:25:05
【问题描述】:

我有以下 urlpatterns:

urlpatterns = patterns('',
   url(r'^$',         'opeiaa.views.home',    name='home'),
   url(r'^store/$',   'opeiaa.views.store',   name='store'),
   url(r'^resume/$',  'opeiaa.views.resume',  name='resume'),
   url(r'^contact/$', 'opeiaa.views.contact', name='contact'),
   url(r'^gallery/',  include('gallery.urls')),

   url(r'^admin/',    include(admin.site.urls)),
)

...并且正在使用这种模板标签:

<a class='nav-link' href='{% url 'contact' %}'>Contact</a>

URL 在页面中呈现为http://localhost:8000/contact/。一切正常,使用./manage.py runserver 进行测试时...

...但随后我运行./manage.py runfcgi - 然后当我导航到联系人页面时,导航中的 URL 指向 http://localhost:8000/contact/contact/!我尝试在开头添加一个斜杠以使 URL 成为绝对 URL,但没有它,URL 似乎是绝对的。

我使用 nginx 作为前端,相关配置如下:

location / {
    include fastcgi_params;
    fastcgi_pass unix:/tmp/django.sock;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_pass_header Authorization;
    fastcgi_intercept_errors off;
}

我正在使用 Django 1.6 和 Python 2.7.4。有人有什么见解吗?

【问题讨论】:

    标签: django nginx flup


    【解决方案1】:

    8 个月后,当它发生在我的另一个网站上时,我发现了这一点,因为 SCRIPT_NAME 被设置在 include fastcgi_params 之前!

    最终的工作配置 sn-p:

    location / {
        include fastcgi_params;
        fastcgi_param SCRIPT_NAME "";
        fastcgi_pass unix:/tmp/django.sock;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_pass_header Authorization;
        fastcgi_intercept_errors off;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-04
      • 2019-11-26
      • 2019-09-18
      • 1970-01-01
      • 1970-01-01
      • 2016-12-17
      相关资源
      最近更新 更多