django网址问题

时间:2016-05-12 16:11:44

标签: python django

这是我的问题:当我完成编码时,我使用`

python manage.py runserver 4444

该应用程序工作正常。 但是,当我把它放入Elastic Compute Service时,它引发了url问题(404) 我不明白,因为它可以在我的电脑上运行!当我把它上线时为什么它不起作用?

Page not found (404)
Request Method: GET
Request URL:    http://121.42.40.115/notebook/homepage
Using the URLconf defined in project.urls, Django tried these URL patterns, in this order:
^admin/
^notebook/ ^/homepage/$ [name='homepage']
^notebook/ ^/homepage2/$ [name='homepage2']
^notebook/ ^(?P<post_id>[0-9]+)/$ [name='detail']
^notebook/ ^(?P<post_id>[0-9]+)/delete/$ [name='delete']
^notebook/ ^edit/(?P<post_id>[0-9]+)/$ [name='edit']
^notebook/ ^/post/$ [name='post']
^notebook/ ^subject(?P<id>\w+)/$ [name='show_subject']
^notebook/ ^/create_subject/$ [name='create_subject']
^notebook/ ^/login_result/$ [name='login_result']
^notebook/ ^$ [name='login']
^notebook/ ^login_result/$ [name='login_result']
^notebook/ ^login_out/$ [name='login_out']
^notebook/ ^log_up/$ [name='log_up']
^notebook/ ^register_done/$ [name='register_done']
^media\/(?P<path>.*)$
^static\/(?P<path>.*)$
The current URL, notebook/homepage, didn't match any of these.

这是我在urls.py中的相关代码

urlpatterns = [
url(r'^/homepage/$', views.homepage, name='homepage'),
url(r'^/homepage2/$', views.homepage2, name='homepage2'),
url(r'^(?P<post_id>[0-9]+)/$', views.detail, name='detail'),
url(r'^(?P<post_id>[0-9]+)/delete/$', views.delete, name='delete'),
url(r'^edit/(?P<post_id>[0-9]+)/$', views.edit, name='edit'),
url(r'^/post/$', views.post, name='post'),
# url(r'^category(?P<category>\w+)/$', views.show_category, name='show_category'),
url(r'^subject(?P<id>\w+)/$', views.show_subject, name='show_subject'),
url(r'^/create_subject/$', views.create_subject, name='create_subject'),
url(r'^/login_result/$', views.login_result, name='login_result'),
url(r'^$', views.login, name='login'),
url(r'^login_result/$', views.login_result, name='login_result'),
url(r'^login_out/$', views.login_out, name='login_out'),
url(r'^log_up/$', views.log_up, name='log_up'),
url(r'^register_done/$', views.register_done, name='register_done'),
# url(r'/upload_image/$', views.upload_image, name='upload_image'),
]

为什么会这样?这对我没有任何意义。请帮我解决一下。

1 个答案:

答案 0 :(得分:0)

从网址模式中删除前导斜杠

例如,它应该是

url(r'^homepage/$', views.homepage, name='homepage'),

而不是

url(r'^/homepage/$', views.homepage, name='homepage'),

请注意,您的网址格式有尾部斜杠,因此您应该转到

http://example.com/notebook/homepage/

而不是

http://example.com/notebook/homepage

通常这没关系,Django会使用尾部斜杠重定向到url。