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

5
我正在跟随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

请求的URL /hello 没有结尾斜杠 (/)。您可以通过添加 ? 使url模式匹配 / 成为可选项:

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

1
哇,localhost/hello 是问题所在...我应该使用 localhost:8000/hello....啊哈哈 - bezzoon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接