python - 无法将 extra_option 与路径 django 一起使用

标签 python django

我不明白为什么我不能使用此处记录的 path() 方法:https://docs.djangoproject.com/en/2.0/topics/http/urls/#passing-extra-options-to-view-functions在我的应用程序中urls.py

这是我的代码:

from django.conf.urls import url, include
from django.contrib import admin
from django.urls import path
from . import views as AliasViews
from permissions import views as PermissionsViews

    urlpatterns = [
    ...
        path(r'^user/(?P<alias_id>\d{1,})/members/?$', 
             AliasViews.UserAliasMember.as_view(), 
             name='useralias_member', {'alias_type':'UserAlias'}),
    ...    
    ]

我收到此错误:SyntaxError:关键字 arg 之后非关键字 arg

最佳答案

这与 path 无关功能。正如错误所示,Python 语法不允许关键字参数 - 例如 name='useralias_member' - 在非关键字参数之前。您的额外字典应该位于名称参数之前。

但请注意,您也感到困惑 pathurl 。新path函数不使用正则表达式,它使用特殊的 <arg:type>格式。如果您想使用正则表达式,请切换回 url .

关于python - 无法将 extra_option 与路径 django 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47757499/

相关文章:

python - 如何在 Windows 10 上安装 cython 和 Anaconda 64 位?

python - Pandas +群

python - Django Rest Framework 多个数据库

Django/admin/页面未显示

Django,多对多字段

python - 属性错误 : 'Price' object has no attribute 'update'

python - 使用Elasticsearch DSL索引数据时出错

python - 如何在 Python 中对角化稀疏 csr 一维矩阵(向量)?

python - 字典理解索引错误

python - 在Python中首次使用惯用语时构造