405 error occurred when ajax submitted wtform

background:
A web system developed using flask. The background user management adopts load mode without refreshing dynamic loading
1, as shown in the picture, click "Yanzhou Mining Group", and dynamically load the page on the right

html:usermanage.html,:


:


:usermanage_ajax.html:


:


2
adduserformwtform

:


adduser:


usermanage_ajax.htmlajaxpostadduser:



:

.

I probably understand that it is because of the request made from system/usermanage, and referer points to system/usermanage, so I return here, but because I did not set the POST method for the view function of system/usermanage, I reported this error. What I want to ask is how to handle this? So that he can achieve the effect I need (showing the notice.html view, that is, a similar effect)

3. The method I have tried
if you write url to the action of form instead of using ajax post, in usermanage_ajax.html, the program will not report an error when executed at this place, but it does not seem to display a verification error message on the current page without using ajax

try:
                    general.SQL(sql)
                    info["type"] = "success"
                    info["title"] = ""
                    info["notice"] = "" + username + " "
                    print("")
                    return render_template("notice.html", info=info) -sharp
                except Exception as error:
                    print(request.path, error)
                    info["type"] = "warning"
                    info["title"] = ""
                    info["notice"] = ""
                    return render_template("notice.html", info=info)

4. Please help me. I have been stuck with this question for 3 days. Thank you very much. Half-way monk programmer, level comparison
summary, do not let him have 405 errors, can normally return to my notice view
5, P.S. Another question is why wtforms validation can still be submitted even if there is an error. Shouldn"t we stop and wait for correction input?
if it is empty, the page will not be submitted, but for example, the mailbox is filled in, but the format is incorrect, or the number of digits on the phone is incorrect (I have crawled the error at the backend), but why is the page still submitted? (then the 405 error is displayed)

Mar.03,2022

is my problem described in less detail? How come there is no answer from the passer-by?


this is your original code:

@app.route('/system/usermanage/')
@login_required
def usermanage():
    current_time = datetime.utcnow()
    groups = general.Groups()
    return render_template('system/usermanage.html', groups=json.dumps(groups), current_time=current_time)

I suggest you try it like this

@app.route('/system/usermanage/', methods=['GET','POST'])
...
...
...

or you can take a look at my article, which is based on websocket-- A preliminary study of flask-socketio-based CRUD Operation

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e450c3-4c20b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e450c3-4c20b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?