在此服务器 django 上找不到请求的 URL

Posted

技术标签:

【中文标题】在此服务器 django 上找不到请求的 URL【英文标题】:the requested URL was not found on this server django 【发布时间】:2014-12-13 16:34:37 【问题描述】:

我正在关注 youtube 教程,但遇到错误...

遇到错误

The requested URL /hello was not found on this server.

网站/urls.py

urlpatterns = patterns('',
    url(r'^hello/$', article.views.hello),
    ...
)

文章/views.py

from django.shortcuts import render
from django.http import HttpResponse

def hello(request):
  name = 'mike'
  html = '<html><body> sup %s </body></html> ' %name
  return HttpRequest(html)

网站/settings.py

INSTALLED_APPS = (
    ...
    'article',
)

【问题讨论】:

【参考方案1】:

请求 URL /hello 没有尾部斜杠 (/)。您可以通过附加 ? 来使 url 模式匹配 /

url(r'^hello/?$', article.views.hello),

【讨论】:

哇。 localhost/hello 是问题..我应该使用 localhost:8000/hello ....aaahhh

以上是关于在此服务器 django 上找不到请求的 URL的主要内容,如果未能解决你的问题,请参考以下文章