Django Admin Kink with Collapse Fieldsets

时间:2011-10-03 17:10:47

标签: django django-admin

我无法在管理控件中显示collapse字段集。最重要的是,每当我进入管理控件时,我偶尔也会出现加载错误,这似乎只是出现了。我不能把这些错误拼凑起来猜测导致问题的原因,但是当我在admin.py中包含所包含的代码时,我似乎只能重现它。

管理员布局错误

Admin layout error

admin.py

from forum.models import Category, Thread, Post
from django.contrib import admin

class PostAdmin(admin.ModelAdmin):
  fieldsets = [
    (None, {'fields': ['author']}),
    (None, {'fields': ['thread']}),
    (None, {'fields': ['creation_date']}),
    (None, {'fields': ['content'], 'classes': ['collapse']}),
    (None, {'fields': ['is_removed']}),
    (None, {'fields': ['agrees'], 'classes': ['collapse']}),
    (None, {'fields': ['thanks'], 'classes': ['collapse']}),
    (None, {'fields': ['saves'], 'classes': ['collapse']}),
  ]

  admin.site.register(Post, PostAdmin)

(偶尔)错误

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 284, in run
    self.finish_response()
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 324, in finish_response
    self.write(data)
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 403, in write
    self.send_headers()
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 467, in send_headers
    self.send_preamble()
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 385, in send_preamble
    'Date: %s\r\n' % http_date()
  File "C:\Python27\lib\socket.py", line 324, in write
    self.flush()
  File "C:\Python27\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 64523)
Traceback (most recent call last):
  File "C:\Python27\lib\SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 570, in __init__
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "C:\Python27\lib\SocketServer.py", line 641, in __init__
    self.finish()
  File "C:\Python27\lib\SocketServer.py", line 694, in finish
    self.wfile.flush()
  File "C:\Python27\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine

任何可能导致此问题的想法?

编辑: 经过仔细审核后,即使折叠的字段被注释掉,错误仍然存​​在。布局问题可能与此错误有关或完全分开。我希望看到两者都固定,显然。

这是一个看似不同的错误:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 284, in run
    self.finish_response()
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 324, in finish_response
    self.write(data)
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 403, in write
    self.send_headers()
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 467, in send_headers
    self.send_preamble()
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 385, in send_preamble
    'Date: %s\r\n' % http_date()
  File "C:\Python27\lib\socket.py", line 324, in write
    self.flush()
  File "C:\Python27\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 50055)
Traceback (most recent call last):
  File "C:\Python27\lib\SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 570, in __init__
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "C:\Python27\lib\SocketServer.py", line 641, in __init__
    self.finish()
  File "C:\Python27\lib\SocketServer.py", line 694, in finish
    self.wfile.flush()
  File "C:\Python27\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053] An established connection was aborted by the software in your host machine

相关的admin.py

from forum.models   import Category, Thread, Post
from django.contrib import admin

class ThreadAdmin(admin.ModelAdmin):
    "Thread layout in the admin control panel."

# Actions
    def admin_lock(self, request, queryset):
        rows_updated = queryset.update(is_locked=True)
        if rows_updated == 1:
            message_bit = "1 thread was"
        else:
            message_bit = "%s threads were" % rows_updated
        self.message_user(request, "%s successfully marked as locked" % message_bit)
    admin_lock.short_description = "Lock selected threads"

    def admin_unlock(self, request, queryset):
        rows_updated = queryset.update(is_locked=False)
        if rows_updated == 1:
            message_bit = "1 thread was"
        else:
            message_bit = "%s threads were" % rows_updated
        self.message_user(request, "%s successfully marked as unlocked" % message_bit)
    admin_unlock.short_description = "Unlock selected threads"

    def admin_remove(self, request, queryset):
        rows_updated = queryset.update(is_removed=True)
        if rows_updated == 1:
            message_bit = "1 thread was"
        else:
            message_bit = "%s threads were" % rows_updated
        self.message_user(request, "%s successfully marked as removed" % message_bit)
    admin_remove.short_description = "Remove selected threads"

    def admin_restore(self, request, queryset):
        rows_updated = queryset.update(is_removed=False)
        if rows_updated == 1:
            message_bit = "1 thread was"
        else:
            message_bit = "%s threads were" % rows_updated
            self.message_user(request, "%s successfully marked as restored" % message_bit)
    admin_restore.short_description = "Restore selected threads"

    actions        = ['admin_lock', 'admin_unlock',
                      'admin_remove', 'admin_restore']
    date_hierarchy =  'creation_date'
    list_display   = ('title', 'category', 'author',
                      'relative_date', 'creation_date')
    list_filter    = ('category',) # Doesn't work
    search_fields  = ['title', 'author']

class PostAdmin(admin.ModelAdmin):
    "Post layout in the admin control panel."

# Actions
    def admin_remove(self, request, queryset):
        rows_updated = queryset.update(is_removed=True)
        if rows_updated == 1:
            message_bit = "1 post was"
        else:
            message_bit = "%s posts were" % rows_updated
        self.message_user(request, "%s successfully marked as removed" % message_bit)
    admin_remove.short_description = "Remove selected posts"

    def admin_restore(self, request, queryset):
        rows_updated = queryset.update(is_removed=False)
        if rows_updated == 1:
            message_bit = "1 post was"
        else:
            message_bit = "%s posts were" % rows_updated
        self.message_user(request, "%s successfully marked as restored" % message_bit)
    admin_restore.short_description = "Restore selected threads"

    actions        = ['admin_remove', 'admin_restore']
    date_hierarchy =  'creation_date'
    list_display   = ('thread', 'author',
                      'relative_date', 'creation_date')
    list_filter    = ('thread',)
    search_fields  = ['thread', 'author']

admin.site.register(Category)
admin.site.register(Thread, ThreadAdmin)
admin.site.register(Post, PostAdmin)

相关问题

  1. Django runserver error
  2. Error on display static content

1 个答案:

答案 0 :(得分:2)

问题是这个(和类似的)行:

(None, {'fields': ['agrees'], 'classes': ['collapse']}),

当字段集标题为None时,没有字段集标题,因此无需单击以展开字段集。 Django错误跟踪器中的This comment,虽然陈旧,但表示不使用标题和collapse是一个坏主意(tm)而你“不应该这样做。”

至于您的其他问题,您的操作系统存在某种形式的问题。它只是意味着建立了一个连接(到你的Python服务器),但你的计算机(你的主机)在Python完成它之前终止了连接。

这个问题有点陈旧但是对于像“django fieldset collapse不起作用”这样的搜索结果仍然相当高,所以我想我可能会为未来的搜索者回答它。