不为成仙,只为在这红尘中等你回来。

您现在的位置是:网站首页>>Django

天天生鲜 ?: (2_0.W001) Your URL pattern '^' has a route that contains '(?P<', begins with a '^', or ends

2019年8月8日 23:50 | 分类:Django | 标签: Python Django

问题描述

Python3.5 + Django2.2 天天生鲜项目在迁移数据库($ python3 manage.py makemigrations)时出现如下报错:

WARNINGS:
?: (2_0.W001) Your URL pattern '^' 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 '^cart/' 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 '^order/' 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 '^tinymce/' 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 '^user/' has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path().

出错原因

从 Django2.0 开始,urls.py 配置方法有很大改变。

解决方法

dailyfresh/dailyfresh/urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('tinymce/', include('tinymce.urls')),  # 富文本编辑器
    path('user/', include(('user.urls', "user"), namespace='user')),
    path('cart/', include(('cart.urls', "cart"), namespace='cart')),
    path('order/', include(('order.urls', "order"), namespace='order')),
    path('', include(('goods.urls', "goods"), namespace='goods')),
]

参考

Django2.+ path配置