有没有类似“rake paths”的东西?在 Django 中?
在 Rails 中,可以使用 rake 显示活动路线 (http://guides.rubyonrails.org/routing.html ):
$ rake routes
users GET /users {:controller=>"users", :action=>"index"}
formatted_users GET /users.:format {:controller=>"users", :action=>"index"}
POST /users {:controller=>"users", :action=>"create"}
POST /users.:format {:controller=>"users", :action=>"create"}
django 是否有类似的工具/命令显示 URL 模式、模式名称(如果有)以及视图中的关联函数?
In rails, on can show the active routes with rake (http://guides.rubyonrails.org/routing.html):
$ rake routes
users GET /users {:controller=>"users", :action=>"index"}
formatted_users GET /users.:format {:controller=>"users", :action=>"index"}
POST /users {:controller=>"users", :action=>"create"}
POST /users.:format {:controller=>"users", :action=>"create"}
Is there a similar tool/command for django showing the e.g. the URL pattern, the name of the pattern (if any) and the associated function in the views?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
已找到 https://github.com/django-extensions/django-extensions:
Have found https://github.com/django-extensions/django-extensions:
一项实验...
现在,如果运行
python urls.py
...An experiment ...
Now, if one runs
python urls.py
...当我尝试 miku 的回答时,出现以下错误:
看起来问题来自于在我的 urls.py 中使用 django.contrib.admin.autodiscover() ,所以我可以将其注释掉,或者在之前正确加载 Django转储 URL。当然,如果我想在映射中查看管理 URL,我无法将它们注释掉。
我发现的方法是创建一个 自定义管理命令转储网址。
When I tried miku's answer, I got this error:
It looks like the problem comes from using
django.contrib.admin.autodiscover()
in myurls.py
, so I can either comment that out, or load Django properly before dumping the URL's. Of course if I want to see the admin URL's in the mapping, I can't comment them out.The way I found was to create a custom management command that dumps the urls.
admindocs 有类似的功能。但它不显示 URL 名称。
admindocs has a similar feature. But it doesn't display URL names.