请求的URL在此服务器上未找到 Django

5 投票
1 回答
7947 浏览
提问于 2025-04-28 05:44

我在看一个YouTube教程的时候,遇到了一个错误...

出现了一个错误

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

site/urls.py

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

article/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)

site/settings.py

INSTALLED_APPS = (
    ...
    'article',
)
暂无标签

1 个回答

5

请求的链接 /hello 后面没有斜杠 (/)。你可以通过在链接模式后面加上一个问号 (?) 来让它可以选择性地匹配带斜杠的情况:

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

撰写回答