为什么会在网址中添加额外的斜杠?

时间:2011-08-14 13:35:35

标签: django dotcloud

我使用django创建了一个博客,并在dotcloud http://www.honeybunny.dotcloud.com/blog/上托管了它在localhost上正常工作但是当我尝试在线访问它时,会在URL上添加额外的斜杠,这可能是什么原因?

  

www.sitename.com/admin /

变为

  

www.sitename.com//admin /

我的urls.py如下

from django.conf.urls.defaults import patterns, include, url
from django.views.generic.simple import redirect_to

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
import blog
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$',redirect_to,{'url':'/blog'}),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^blog/',include('blog.urls')),
)

同时在管理员上提交登录表单会将我重定向到http://admin/,而在本地环境中,它可以正常运行。

更新:我的问题与here描述的问题非常相似。

3 个答案:

答案 0 :(得分:0)

从django教程中,url文件应该如下所示。

from django.conf.urls.defaults import *

urlpatterns = patterns('', (r'^articles/2003/$', 'news.views.special_case_2003'),
(r'^articles/(\d{4})/$', 'news.views.year_archive'),
(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'), )

答案 1 :(得分:0)

from django.conf.urls.defaults import patterns, include, url
from django.views.generic.simple import redirect_to

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

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

            # Uncomment the admin/doc line below to enable admin documentation:
                # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

                    # Uncomment the next line to enable the admin:
                        url(r'^$',redirect_to,{'url':'/blog'}),
                            url(r'^admin/$', include(admin.site.urls)),
                                )

我的urls.py档案是 Django Admin

我删除了import blog行,因为我没有博客模块。

答案 2 :(得分:0)

当我将它上传到epio时,相同的代码工作没有任何错误似乎是dotcloud的一个问题