添加CRUD实例化功能

2024-04-19 20:56:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Plotly Dash完成一项作业,我对其中一项任务有疑问

该任务要求我“在回调例程中添加用于实例化CRUD对象的功能”

我需要添加允许用户在输入框中添加用户名和密码的功能,以便对用户进行身份验证。我是新手,不知道从哪里开始

我在代码底部的注释中指出了问题区域,即TODO:

任何建议都将不胜感激!谢谢大家!

这是我的密码:

app = JupyterDash('ModuleFive')

# the application interfaces are declared here
# this application has two input boxes, a submit button, a horizontal line and div for output
app.layout = html.Div(
    [
    
    html.H1("Zane's Module 5 Assignment"),
    html.Hr(),
        
        dcc.Input(
            id="input_user".format("text"),
            type="text",
            placeholder="input type {}".format("text")),
        dcc.Input(
            id="input_passwd".format("password"),
            type="password",
            placeholder="input type {}".format("password")),
        html.Button('Execute', id='submit-val', n_clicks=0),
        
    html.Hr(),
    html.Div(id="query-out"),
    #Completed: inserted unique identifier code on line 20 and 36
    html.H3('Fin'),
    ])

# this is area to define application responses or callback routines
# this one callback will take the entered text and if the submit button is clicked then call the 
#  mongo database with the find_one query and return the result to the output div
@app.callback(
    Output("query-out", "children"),
    [Input("input_user".format("text"), "value"), 
     Input("input_passwd".format("password"),"value"),
     Input('submit-val', 'n_clicks')],
    [dash.dependencies.State('input_passwd', 'value')]
)
def cb_render(userValue,passValue,n_clicks,buttonValue):
    if n_clicks > 0:
        ###########################
        # Data Manipulation / Model
        # use CRUD module to access MongoDB
        ##########################
        username = urllib.parse.quote_plus(userValue)
        password = urllib.parse.quote_plus(passValue)
        #TODO: Instantiate CRUD object with above authentication username and password 

价值观


Tags: andthetextidappformatinputapplication