I'm hosting my Django app on Heroku and my domain name is registered with Network Solutions. When I enter my domain name, ie www.example.com, Heroku displays:
"Not Found
The requested URL / was not found on this server."
I then have to navigate to the template's URL that displays my app's landing page, www.example.com/shipment/.
How can I get my root domain www.example.com to automatically redirect to www.example.com/shipment/, or alternatively, change the URL of /shipment/ to my root domain?
Here's the urls.py for my app:
from django.conf.urls import patterns, url
from shipment import views
urlpatterns = patterns('',
url(r'^$', views.landing, name='landing'),
url(r'^create-subscription/$', views.createSubscription, name='createSubscription'), #
url(r'^(?P<subscription_duration>\d+)/create-account/$', views.createAccount, name='createAccount'),
url(r'^create-account/pay/$', views.pay, name='pay'),
url(r'^create-account/confirm/$', views.confirm, name='confirm'),
)
Here's the urls.py for my project:
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'subscription.views.home', name='home'),
# url(r'^subscription/', include('subscription.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'^shipment/', include('shipment.urls', namespace = "shipment")),
url(r'^admin/', include(admin.site.urls)),
)
I changed:
url(r'^shipment/', include('shipment.urls', namespace = "shipment")),
to
url(r'^', include('shipment.urls', namespace = "shipment")),
and that fixed it!
Your problem is this line:
url(r'^shipment/', include('shipment.urls', namespace = "shipment")),
It means "include all these URLs but they must start with "shipment/".
You could add a line to your site's urls.py like:
url(r'^$', generic.RedirectView(url='/shipment/', permanent=False)),
(and then also put a corresponding "from django.views import generic" at the top of your file).
This map your URL / to a redirect view that redirects to /shipment/.
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.