我正在尝试使用 Django 的内置管理文档功能来使编写模板变得更容易。假设如果您转到 /admin/docs/views 您应该获得应用程序中每个视图的文档。我看到一个列表,但没有一个链接有效
:-) 列出的与我的应用程序相关的任何视图都会转到一个空白页面,除了视图名称作为标题之外什么都没有。
-) 当我点击与管理相关的视图时,它们都会给我带来 Django 404 错误,除了那些与文档本身相关的视图。与文档相关的链接也给我空白页。 (即单击 /admin/doc/filters 会出现一个空白页面,只有“django.contrib.admindocs.views.template_filter_index”作为标题,但单击 /admin/auth/user 会出现 Django 404 错误
404 错误导致我怀疑我的 URLconf 是错误的,但我所做的只是取消注释内置行:
# Uncomment the admin/doc line below to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
我不知道如何处理空白页面,就像我一样。知道你需要在模型上提供 get_absolute_url 才能使某些管理功能正常工作吗?
即使没有人知道答案,任何有关管理文档功能的文档都会有用 - 我一直在 Google 上搜索(并搜索 StackOverflow) )并且此功能似乎很少有记录,
谢谢!
I'm trying to use Django's built-in admin docs feature to make writing templates easier. Supposedly if you go to /admin/docs/views you should get documentation for every view in your application. I see a list, but none of the links work:
-) Any view listed that's related to my application just goes to a blank page with nothing but the name of the view as a header.
-) The views related to admin all give me Django 404 errors when I click on them, except those that are related to the docs itself. The docs-related links also give me blank pages. (i.e. clicking /admin/doc/filters gives a blank page with nothing but "django.contrib.admindocs.views.template_filter_index" as a title, but clicking /admin/auth/user gives me a Django 404 error
The 404 errors lead me to suspect my URLconf is wrong, but all I did was uncomment the built-in lines. The relevant sections read:
# Uncomment the admin/doc line below to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
And I have no idea what to make of the blank pages. Do I need to provide some extra meta information somewhere, like I know you need to provide the get_absolute_url on models for some of the admin features to work right?
Even if no one knows the answer, any documentation on the admin docs feature would be useful -- I've been Google all over (and searching StackOverflow) and this feature seems very little-documented.
Thanks!
发布评论
评论(2)
您需要将
'django.contrib.admindocs'
添加到settings.py
中的INSTALLED_APPS
中。它应该已经在那里并被注释掉了。不过,如果urls.py
中的评论提到它就好了... 来源。You need to add
'django.contrib.admindocs'
to yourINSTALLED_APPS
insettings.py
. It should already be there and commented out. Though it would be nice if the comment inurls.py
mentioned it ... Source.我以前从未查看过视图管理文档页面——我从来没有必要这样做。 B4你是对的,它们似乎缺乏潜在的功能。
如果您为视图函数提供文档字符串(文档),该内容将出现在您的“空白页”上。
大多数(不,是全部)管理站点视图实际上都是
admin.sites.AdminSite
的修饰成员方法。我环顾四周,我的一个使用装饰器的视图也受到了 404 的影响。负责视图详细信息的视图开始:
您可以看到它尝试导入视图以从中获取信息;如果视图实际上是一个装饰器(可能使用内部函数来包装真实视图),则它将无法导入它。例如,如果您在 django shell 中执行
from django.contrib.admin.sites import index
,您将得到一个 ImportError ,而django.contrib.admin.site.index
> (注意单数site
)是:<>< 的绑定方法 AdminSite.index 此外,我的代码
片段中的最后一行似乎表明,如果您想弄清楚
util.parse_docstring
使用的模板,则可以更好地控制这些页面上显示的内容。I've never looked at the views admin doc pages before -- I've never had a need to. B4ut you're right, they seem to be -- lacking in potential features.
If you give your views functions docstrings (documentation), that content will appear on your "blank pages".
Most -- no, all -- of the admin sites views are actually decorated member methods of
admin.sites.AdminSite
. I looked around, and a view of mine which uses a decorator also suffers from the 404.The view responsible for view details starts:
You can see it tries to import the view to get info from it; if the view is actually a decorator (which probably used an internal function to wrap the real view), it won't be able to import it. eg, if you do
from django.contrib.admin.sites import index
in a django shell, you'll get an ImportError, whereasdjango.contrib.admin.site.index
(note the singularsite
) is a:<bound method AdminSite.index of <django.contrib.admin.sites.AdminSite object at 0x...>>
Further, that last line in my snippet seems to indicate that there's a capability for finer control over what shows up on those pages, if you care to figure out the template that
util.parse_docstring
uses.