未找到主页的PythonAnywhere Django 404页面

时间:2015-01-18 05:29:36

标签: python django http-status-code-404 pythonanywhere

我知道有类似这样的帖子。我已经对它进行了审核,这与我目前在Pythonanywhere.com

上遇到的情况完全不同

我正在尝试将我通过tangowithdjango.com完成的rango教程项目部署到Pythonanywhere.com上。当我尝试打开网站(网址是ragzputin.pythonanywhere.com)时,我看到了这个页面:

enter image description here

这是我的项目的urls.py文件:

from django.conf.urls.defaults import *
from django.conf import settings

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',

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

if settings.DEBUG:
urlpatterns += patterns(
    'django.views.static',
    (r'media/(?P<path>.*)',
    'serve',
     {'document_root': settings.MEDIA_ROOT}), )

如果你们需要一些额外的信息,这里是我的app urls.py(应用名称是rango):

from django.conf.urls import patterns, url
from rango import views

urlpatterns = patterns('',
    url(r'^$', views.index, name="index"),
    url(r'^about/$', views.about, name="about"),
    url(r'^add_category/$', views.add_category, name="add_category"),
    url(r'^category/(?P<category_name_url>\w+)/add_page/$', views.add_page,   name="add_page"),
    url(r'^category/(?P<category_name_url>\w+)/$', views.category, name="category"),
    url(r'^register/$', views.register, name="register"),
    url(r'^login/$', views.user_login, name="login"),
    url(r'^restricted/$', views.restricted, name="restricted"),
    url(r'^logout/$', views.user_logout, name="logout"),
    url(r'^profile/$', views.profile, name="profile"),
    url(r'^goto/$', views.track_url, name="track_url"),
    url(r'^like_category/$', views.like_category, name="like_category"),
    url(r'^suggest_category/$', views.suggest_category, name="suggest_category"),
    url(r'^auto_add_page/$', views.auto_add_page, name="auto_add_page"),
)

从上面的404页面可以看出,服务器无法进入以“^ rango /”开头的主页面。有什么建议吗?

1 个答案:

答案 0 :(得分:5)

您应该将主页的网址添加到项目的urls.py:

urlpatterns = patterns('',
    url(r'^$', 'rango.views.index', name="index"),
    url(r'^rango/', include('rango.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

并且不要忘记从rango/urls.py删除相同的(第一个)网址。

另一个选项是添加从//rango/的重定向。如果您选择此选项,则项目的urls.py应为:

from django.views.generic.base import RedirectView

urlpatterns = patterns('',
    url(r'^$', RedirectView.as_view(url='/rango/')),
    url(r'^rango/', include('rango.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

当然,在这种情况下,rango/urls.py应该不受影响。