【问题标题】:What is .<format> argument for?.<format> 参数是什么?
【发布时间】:2017-11-14 08:57:25
【问题描述】:
  • Django==1.11

  • django-extensions==1.9.7

    /api/userprofiles/<pk>/   poinkbackend.apps.userprofiles.api.viewsets.UserProfileViewset  api:userprofile-detail
    /api/userprofiles/<pk>\.<format>/ poinkbackend.apps.userprofiles.api.viewsets.UserProfileViewset  api:userprofile-detail
    /a
    

文档说

show_urls - 显示项目中定义的 url 路由。在这一点上非常粗糙。

我用format关键字搜索过。但结果与我的问题无关。

它是否代表?format=json 参数?

我曾尝试用 html、xml 替换 json。我得到了错误的回报。

参考: http://django-extensions.readthedocs.io/en/latest/command_extensions.html?highlight=show_urls

【问题讨论】:

  • 其实你需要做的是弄清楚poinkbackend 是什么,然后去看看它的来源。在它的 API 视图中,它会告诉你 kwarg format 应该做什么,这会解释它。
  • 我从未在视图中查看过format。感谢您的关注。

标签: python django django-extensions


【解决方案1】:

在该 URL 模式中,format 是 URL 模式中的关键字参数(与查询字符串中的 ?format=json 不同)。匹配的 URL 是:

/api/userprofiles/5.json/

【讨论】:

  • 从来不知道它也有这种模式。我通常使用/api/userprofiles/5/?format=json
猜你喜欢
  • 1970-01-01
  • 2017-09-14
  • 2023-04-10
  • 2013-12-17
  • 2011-07-02
  • 2022-06-10
  • 2017-10-31
  • 1970-01-01
相关资源
最近更新 更多