简体   繁体   中英

PythonAnywhere Django 404 Page Not Found for Homepage

I know there is a similar post like this one. I've reviewed it and it is quite different from what I'm experiencing at the moment on Pythonanywhere.com

I'm trying to deploy my rango tutorial project that I completed through tangowithdjango.com onto Pythonanywhere.com. When I try to open the site (url is ragzputin.pythonanywhere.com), I get this page:

在此输入图像描述

Here's my urls.py file for my project:

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}), )

If you guys need some extra information, here's my app urls.py (app name is 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"),
)

As you can see from the 404 page above, the server is not able to get to the main page which starts with '^rango/'. Any suggestions?

You should add url for home page into the project's urls.py:

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

And don't forget to remove the same (first) url from rango/urls.py .

The other option is to add redirect from / to /rango/ . If you choose this option then project's urls.py should be:

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)),
)

Of course in this case rango/urls.py should be untouched.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM