找不到Django URL

2024-04-18 21:07:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Django的新手,使用本教程学习https://docs.djangoproject.com/en/1.6/intro/tutorial03/ 线路有点问题。在

查看代码:

def index(request):
    return HttpResponse(r'<h3 style="font-style: bold;">Index</h3>')

URL配置代码:

1。博客/url

^{pr2}$

2.项目/url

  urlpatterns = patterns('',
        url(r'^blog/', include('blog.urls')),
        url(r'^admin/', include(admin.site.urls)),
    )

当我要127.0.0.1:8080/索引

找不到页面(404)

使用les1.URL中定义的URLconf,Django尝试了以下URL模式,顺序如下:

  1. ^博客/
  2. ^管理员/

当前的URL,index,与这些都不匹配。在

项目结构

blog/
    templates
    __init__.py
    admin.py
    models.py
    tests.py
    urls.py
    views.py
les1/
    __init__.py
    settings.py
    urls.py
    wsgi.py
db.sqlite3
manage.py

找不到错误:(


Tags: 项目django代码pyurlindexincludeadmin
2条回答

从视图代码中删除r。在

def index(request): return HttpResponse('<h3 style="font-style: bold;">Index</h3>')

您在浏览器中输入的实际url是什么?是127.0.0.1:8000还是{}?从你的帖子来看,我想是第二个:

The current URL, index, didn't match any of these.

如果您输入127.0.0.1:8000/blog怎么办?在

index是路由的名称,仅在服务器端使用。这是一种快捷方式,用于快速反转和显示URL:

^{pr2}$

相关问题 更多 >