【问题标题】:the requested URL was not found on this server django在此服务器 django 上找不到请求的 URL
【发布时间】: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',
)

【问题讨论】:

    标签: python regex django django-urls


    【解决方案1】:

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

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

    【讨论】:

    • 哇。 localhost/hello 是问题..我应该使用 localhost:8000/hello ....aaahhh
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 2017-03-21
    • 2010-10-16
    • 1970-01-01
    • 1970-01-01
    • 2017-12-26
    • 2015-03-30
    相关资源
    最近更新 更多