Django隐藏输入字段问题

时间:2019-03-12 14:34:41

标签: django modelform

我有以下模型表单,必须在其中添加一个隐藏字段。

2019-03-12 18:16:59 TLS error on connection from localhost (muhammetdemirel.com.tr) [127.0.0.1] (SSL_CTX_use_certificate_chain_file file=/usr/local/vesta/ssl/certificate.crt): error:0200100D:system library:fopen:Permission denied
2019-03-12 18:17:45 TLS error on connection from mail-oi1-f173.google.com [209.85.167.173] (SSL_CTX_use_certificate_chain_file file=/usr/local/vesta/ssl/certificate.crt): error:0200100D:system library:fopen:Permission denied
2019-03-12 18:18:45 TLS error on connection from mail-ot1-f41.google.com [209.85.210.41] (SSL_CTX_use_certificate_chain_file file=/usr/local/vesta/ssl/certificate.crt): error:0200100D:system library:fopen:Permission denied
2019-03-12 18:22:13 TLS error on connection from mail-oi1-f180.google.com [209.85.167.180] (SSL_CTX_use_certificate_chain_file file=/usr/local/vesta/ssl/certificate.crt): error:0200100D:system library:fopen:Permission denied

该表单仅显示隐藏的表单字段,并且不显示“名称”字符字段。当我将字段“ id_sel_comp”标记为未隐藏时,将显示所有字段。这有什么问题? 表单使用以下模板呈现在模板中:

class AddEditGroupForm(forms.ModelForm):
    id_sel_comp = forms.CharField(
        label='selected company',
        initial=0,
        required=True,
        widget=forms.HiddenInput(attrs={'id': 'id_sel_comp'})
    )

    class Meta:
        model = Group
        fields = ('name', 'id_sel_comp')

    def __init__(self, *args, **kwargs):
        super(AddEditGroupForm, self).__init__(*args, **kwargs)
        self.fields['name'].widget.attrs.update({'class': 'form-control m-input form-control-sm'})

    def as_two_col_layout(self):
        return self._html_output(
            normal_row='<div class="form-group m-form__group row"><label class="col-sm-3 col-form-label">%(label)s</label><div class="col-sm-9">%(field)s%(help_text)s</div></div>',
        error_row='%s',
        row_ender='',
        help_text_html=' <span class="m-form__help">%s</span>',
        errors_on_separate_row=True)

1 个答案:

答案 0 :(得分:1)

您没有正确指定program Project2; {$APPTYPE CONSOLE} {$R *.res} uses Windows, Classes, SysUtils, Magnification; type THostWNDThread = class(TThread) private class function WindowProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; static; class function MagImageScalingCallback(hwnd: HWND; srcdata: Pointer; srcheader: MAGIMAGEHEADER; destdata: Pointer; destheader: MAGIMAGEHEADER; unclipped: TRect; clipped: TRect; dirty: HRGN): BOOL; stdcall; static; protected procedure Execute; override; public end; procedure THostWNDThread.Execute; var Msg: TMsg; WndClass: WNDCLASS; hWndMag: HWND; begin with WndClass do begin Style := 0; lpfnWndProc := @WindowProc; cbClsExtra := 0; cbWndExtra := 0; hInstance := HInstance; hIcon := 0; hCursor := LoadCursor(0, IDC_ARROW); hbrBackground := COLOR_WINDOW; lpszMenuName := nil; lpszClassName := 'THostWNDThread'; end; if not Windows.RegisterClass(FWndClass) then RaiseLastOSError; try hWndMag := CreateWindow(WndClass.lpszClassName, nil, DesiredStyles, DesiredXPos, DesiredYPos, DesiredWidth, DesiredHeight, 0, 0, HInstance, nil); if hWndMag = 0 then RaiseLastOSError; try SetWindowLongPtr(hWndMag, GWL_USERDATA, LONG_PTR(Self)); if not MagSetImageScalingCallback(hWndMag, MagImageScalingCallback) then raise Exception.Create('Cant set Scaling callback'); while GetMessage(Msg, hWndMag, 0, 0) > 0 do begin TranslateMessage(msg); DispatchMessage(msg) end; finally DestroyWindow(hWndMag); end; finally Windows.UnregisterClass(WndClass.lpszClassName, HInstance); end; end; class function THostWNDThread.WindowProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin // handle uMsg as needed... Result := DefWindowProc(hwnd, uMsg, wParam, lParam); end; class function THostWNDThread.MagImageScalingCallback(hwnd: HWND; srcdata: Pointer; srcheader: MAGIMAGEHEADER; destdata: Pointer; destheader: MAGIMAGEHEADER; unclipped: TRect; clipped: TRect; dirty: HRGN): BOOL; stdcall; var pThread: THostWNDThread; begin pThread := THostWNDThread(GetWindowLongPtr(hwnd, GWL_USERDATA)); // use pThread and parameters as needed ... Result := True; end; var Thread: THostWNDThread; begin try Thread := THostWNDThread.Create(False); Thread.WaitFor; Thread.Free; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln; end. 。您当前将其设置为“”,这与您指定的row_ender不正确。您的normal_rowrow_ender。这样您的</div></div>就变成了,

as_two_col_layout

希望这会有所帮助!