找不到主页的 PythonAnywhere Django 404 页面
PythonAnywhere Django 404 Page Not Found for Homepage
我知道有一个与此类似的 post。我已经对其进行了审查,它与我目前在 Pythonanywhere.com
上所经历的完全不同
我正在尝试将通过 tangowithdjango.com 完成的 rango 教程项目部署到 Pythonanywhere.com。当我尝试打开网站时(url 是 ragzputin.pythonanywhere.com),我得到这个页面:
这是我的项目的 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}), )
如果你们需要一些额外的信息,这是我的应用程序 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/'开头的主页。有什么建议吗?
您应该将主页的 url 添加到项目的 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
中删除相同的(第一个)url。
另一个选项是添加从 /
到 /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
应该保持不变。
我知道有一个与此类似的 post。我已经对其进行了审查,它与我目前在 Pythonanywhere.com
上所经历的完全不同我正在尝试将通过 tangowithdjango.com 完成的 rango 教程项目部署到 Pythonanywhere.com。当我尝试打开网站时(url 是 ragzputin.pythonanywhere.com),我得到这个页面:
这是我的项目的 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}), )
如果你们需要一些额外的信息,这是我的应用程序 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/'开头的主页。有什么建议吗?
您应该将主页的 url 添加到项目的 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
中删除相同的(第一个)url。
另一个选项是添加从 /
到 /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
应该保持不变。