更新 Django-smart-selects 的 urlpatterns

huangapple go评论65阅读模式
英文:

Updating urlpatterns for django-smart-selects

问题

我正在尝试构建我的第一个Django项目,基于Django文档中的投票示例。

我想要在表单中添加链接/级联下拉菜单,并找到了django-smart-selects。

我阅读了文档,但不确定如何将文档中建议的更新集成到我目前的项目的urls.py urlpatterns中。

链接文档中提到的智能选择URL:

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

我项目中urls.py文件中当前的urlpatterns值:

urlpatterns = [
    path('', include('TimeTracking.urls')),
    path('admin/', admin.site.urls),
    path('data-browser/', include('data_browser.urls')),
]

显然,将这些条目添加到我的urlpatterns = []中不会起作用,但我还是尝试了一下...

NameError: name 'url' is not defined

英文:

I am attempting my first django project by building on top of the polls example from the django documentation.

I would like to add linked/cascading dropdowns to a form and found my way to django-smart-selects.

I read the documentation but wasn't sure how to integrate the suggested updates to project's urls.py urlpatterns from the documentation into what I have currently.

The smart select urls mentioned in the linked documentation

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

The current value of urlpatterns in my project's ursl.py file.

urlpatterns = [
    path('', include('TimeTracking.urls')),
    path('admin/', admin.site.urls),
    path('data-browser/', include('data_browser.urls')),
]

Obviously adding those entries to my urlpatterns = [] wouldn't work but I attemtped it anyway...

> NameError: name 'url' is not defined

答案1

得分: 0

from django.urls import path, re_path
urlpatterns = [
    path('', include('TimeTracking.urls')),
    path('admin/', admin.site.urls),
    re_path(r'^chaining/', include('smart_selects.urls')),
    path('data-browser/', include('data_browser.urls')),
]
英文:

try

from django.urls import path, re_path
urlpatterns = [
            path('', include('TimeTracking.urls')),
            path('admin/', admin.site.urls),
            re_path(r'^chaining/', include('smart_selects.urls')),
            path('data-browser/', include('data_browser.urls')),
        ]

huangapple
  • 本文由 发表于 2023年7月31日 23:05:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804906.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定