Question

I have the following 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)),
)

... and am using this kind of template tag:

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

The URL gets rendered in the page as http://localhost:8000/contact/. Everything works fine, when using ./manage.py runserver for testing...

... but then I run ./manage.py runfcgi - then when I navigate to the contact page, the URL in the navigation points to http://localhost:8000/contact/contact/! I have tried putting a slash at the start to make the URL absolute, but the URLs appear to be absolute without it.

I am using nginx as a frontend, and the relevant config from there is:

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;
}

I am using Django 1.6 & Python 2.7.4. Anyone have any insight?

Was it helpful?

Solution

8 months later I had figured this out when it happened on another one of my sites, because SCRIPT_NAME was being set before include fastcgi_params!

The final working config snippet:

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top