我在Heroku上托管我的Django应用程序,我的域名已在Network Solutions注册。当我输入我的域名,即www.example.com时,Heroku显示:
"Not Found
The requested URL / was not found on this server."
然后,我必须导航到模板的网址,该网址会显示我应用的目标网页www.example.com/shipment/。
如何让我的根域www.example.com自动重定向到www.example.com/shipment/,或者将/ shipment /的URL更改为我的根域?
这是我的应用的urls.py:
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'),
)
这是我项目的urls.py:
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)),
)
答案 0 :(得分:5)
我改变了:
url(r'^shipment/', include('shipment.urls', namespace = "shipment")),
到
url(r'^', include('shipment.urls', namespace = "shipment")),
并修复了它!
答案 1 :(得分:1)
你的问题就在这一行:
url(r'^ shipment /',include('shipment.urls',namespace =“shipment”)),
这意味着“包含所有这些网址,但必须以”shipping /".
开头您可以在网站的urls.py中添加一行,如:
url(r'^ $',generic.RedirectView(url ='/ shipment /',permanent = False)),
(然后还在文件顶部放置了相应的“来自django.views import generic”。)
这会将您的网址映射到重定向到/ shipment /.
的重定向视图