T
T
tteqwe2020-03-31 14:20:46
Flask
tteqwe, 2020-03-31 14:20:46

How to display an error in Flask if it occurred when connecting to the database user while submitting data from the form?

Hello. A question. I send the form with an ajax request, on the server side I accept it and everything is fine, but let's say there was a problem with entering data into the database. I would like the user to see an error that the message did not pass. How can this be implemented?

@app.route('/', methods=['GET', 'POST'])
    def feedBack():
        try:....
    return render_template('index.html', title='Форма обратной связи')
 @app.route('/success', methods=['POST', 'GET'])
    def success():
        try:
            # Получаем данные при отправке формы
            if request.method == 'POST':
           # Далее идет подключение к бд и вставка данных, вот здесь может возникнуть ошибка

Accordingly, the question is: how can I show the user a message, they say. There was an error, please check back later

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-03-31
@trapwalker

Add a field with an error flag and a text explanation to the response structure.
Usually this is shown on the client something like this: "Oh, something went wrong, our support team is already aware and we are doing everything possible to prevent this from happening again. Please try again later or contact our support team with a question through this form <link to the feedback form>".
In order for what was written not to be a lie, it is necessary to log in detail and carefully all the circumstances under which the error occurred, display a notification about the problem on the dashboard and in the mail of the site administration. Upon fixing the problem, you can write to the client in your personal account or email a message with apologies, gratitude for the problem found and a notification that everything has been fixed and you can continue to use the service.
The user does not need to know extra shameful details about your internal jambs, no codes or phrases are also required to be compiled for the user to contact support verbally. Ideally, if support immediately associates the request and the problem through cookies and will be aware of what happened at the first contact. This looks to the user like care and attention to his problem with your service.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question