栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

关于“Python编程:从入门到实践”出现问题的解答

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

关于“Python编程:从入门到实践”出现问题的解答

问题:

WARNINGS:

?: (2_0.W001) Your URL pattern '^$' [name='index'] has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path().

?: (2_0.W001) Your URL pattern '^admin/' has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path().

教程源程序文件:

Learning_log.urls:

from django.conf.urls import include, url

from django.contrib import admin

urlpatterns = [

url(r'^admin/', include(admin.site.urls)),

url(r'', include('learning_logs.urls', namespace='learning_logs')),

]

Learning_logs.urls:

"""定义learning_logs的URL模式"""

from django.conf.urls import url

from . import views

urlpatterns = [

# 主页

url(r'^$', views.index, name='index'),

]

网页显示如下:

 Page not found (404)

Request Method:

GET

Request URL:

http://localhost:8000/

Using the URLconf defined in learning_log.urls, Django tried these URL patterns, in this order:

  1. admin/
  2. ^$ [name='index']

The empty path didn’t match any of these.

You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page. 

更改过后的文件:

Learning_log.urls:

from django.contrib import admin

from django.urls import path, include

urlpatterns = [

    path(r'admin/', admin.site.urls),

    path(r'', include(('learning_logs.urls', 'learning_logs'), namespace='learning_logs')),

]

Learning_logs.urls:

from django.urls import path

from . import views

urlpatterns = [

   path(r'', views.index, name='index')

]

网页显示如下:

Learning Log

Learning Log helps you keep track of your learning, for any topic you're learning about.

达到预期目的!其中正则表达式参数留空是何道理,还不清楚。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/863845.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号