Django在url中重复管理前缀

时间:2014-02-22 19:04:09

标签: python django nginx django-admin

我在Fastcgi模式下运行Django

./manage.py runfcgi method=threaded host=127.0.0.1 port=8080

使用Nginx

server {
    listen 80;
    server_name myhostname.com;
    access_log /var/log/nginx/sample_project.access.log;
    error_log /var/log/nginx/sample_project.error.log;

    location /static/ { # STATIC_URL
        alias /home/www/myhostname.com/static/; # STATIC_ROOT
        expires 30d;
    }

    location /media/ { # MEDIA_URL
        alias /home/www/myhostname/static/; # MEDIA_ROOT
        expires 30d;
    }

    location / {
       include fastcgi_params;
       fastcgi_pass 127.0.0.1:8080;
    }
}

管理员网址

http://myhostname.com/admin/

我注意到生成的每个HTML链接都是错误的,如下面的

 ...
 <a href="/admin/admin/logout/">Log out</a>
 ...

在我的url.py下面


    from django.conf.urls import patterns, include, url

    from django.contrib import admin
    admin.autodiscover()

    urlpatterns = patterns('',
        # Examples:
        # url(r'^$', 'configuratore.views.home', name='home'),
        # url(r'^blog/', include('blog.urls')),

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

似乎Django正在重复管理URL,但我不明白为什么。

1 个答案:

答案 0 :(得分:2)

确保在nginx配置中将fastcgi_param SCRIPT_NAME "";添加到location /块。默认情况下,django会将其值设置为反转网址,因此设置为空网址应该可以使其正常工作。