Django admin/doc/views/ 全部空白或损坏

发布于 2024-09-28 15:46:21 字数 852 浏览 3 评论 0 原文

我正在尝试使用 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅唱々樱花落 2024-10-05 15:46:21

您需要将 'django.contrib.admindocs' 添加到 settings.py 中的 INSTALLED_APPS 中。它应该已经在那里并被注释掉了。不过,如果 urls.py 中的评论提到它就好了... 来源

You need to add 'django.contrib.admindocs' to your INSTALLED_APPS in settings.py. It should already be there and commented out. Though it would be nice if the comment in urls.py mentioned it ... Source.

北斗星光 2024-10-05 15:46:21

我以前从未查看过视图管理文档页面——我从来没有必要这样做。 B4你是对的,它们似乎缺乏潜在的功能。

如果您为视图函数提供文档字符串(文档),该内容将出现在您的“空白页”上。

大多数(不,是全部)管理站点视图实际上都是 admin.sites.AdminSite 的修饰成员方法。我环顾四周,我的一个使用装饰器的视图也受到了 404 的影响。

负责视图详细信息的视图开始:

def view_detail(request, view):
    if not utils.docutils_is_available:
        return missing_docutils_page(request)

    mod, func = urlresolvers.get_mod_func(view)
    try:
        view_func = getattr(import_module(mod), func)
    except (ImportError, AttributeError):
        raise Http404
    title, body, metadata = utils.parse_docstring(view_func.__doc__)
    ...

您可以看到它尝试导入视图以从中获取信息;如果视图实际上是一个装饰器(可能使用内部函数来包装真实视图),则它将无法导入它。例如,如果您在 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:

def view_detail(request, view):
    if not utils.docutils_is_available:
        return missing_docutils_page(request)

    mod, func = urlresolvers.get_mod_func(view)
    try:
        view_func = getattr(import_module(mod), func)
    except (ImportError, AttributeError):
        raise Http404
    title, body, metadata = utils.parse_docstring(view_func.__doc__)
    ...

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, whereas django.contrib.admin.site.index (note the singular site) 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文