我有layout从第二个模块导入的应用程序,然后在返回app.layout到此选项卡内容时将其呈现在选项卡中。我有问题,布局是用输入的默认值导入的,当我输入填充了键并在选项卡之间更改时,当我单击回输入选项卡时,值会重置为默认值“x”。我设法通过在回调中第二次声明布局来解决这个问题,但它看起来不太好,并且需要为进一步的功能编写两次布局。有我的代码:
if 'manager' not in vars():
manager = Recognition('xx', 'xx')
print('defining manager')
lcheck = 0
while lcheck == 0:
layout = [
html.Div([
html.Div(
[
html.H3("Primary API key"),
dcc.Input(
id='primary-key',
value=manager.api_key,
placeholder='Enter a value...',
type='text',
style = {"width":"50%"}
),
html.H3("Private API key"),
dcc.Input(
id='private-key',
value=manager.api_secret,
placeholder='Enter a value...',
type='text',
style = {"width":"50%"}
),
],
),
html.Button('Submit', id='button', className='btn btn-primary'),
html.Div(id='output-hidden')
])
]
lcheck=1
@app.callback(
Output('primary-key', 'value'),
[Input('button', 'n_clicks')],
[State('primary-key', 'value'),
State('private-key', 'value')]
)
def update_output(n_clicks, value1, …Run Code Online (Sandbox Code Playgroud) 我正在学习 Django,但从 CreateView 重定向回来时遇到问题我想重定向到 BookDetail 页面,其中包含由 CreateView 创建的 bookinstance 列表。模型.py:
class BookInstance(models.Model):
"""Model representing a specific copy of a book (i.e. that can be borrowed from the library)."""
id = models.UUIDField(primary_key=True, default=uuid.uuid4, help_text='Unique ID for this particular book across whole library')
book = models.ForeignKey('Book', on_delete=models.SET_NULL, null=True)
imprint = models.CharField(max_length=200)
due_back = models.DateField(null=True, blank=True)
borrower = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
LOAN_STATUS = (
('m', 'Maintenance'),
('o', 'On loan'),
('a', 'Available'),
('r', 'Reserved'),
)
status = models.CharField(
max_length=1,
choices=LOAN_STATUS,
blank=True,
default='m',
help_text='Book …Run Code Online (Sandbox Code Playgroud)