I have a simple web app to message (using Twilio API) selected respondents with the following code:
app.py
client = Client(account_sid, auth_token)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/send_sms',methods=['POST'])
def send_sms():
message = request.form['message']
selected_groups = request.form.getlist('groups')
selected_secretariat_member = request.form.get('selected_secretariat_member')
# more code ...
return redirect(url_for('index'))
templates/index.html
<div class="container mt-5">
<h1 class="text-center">Send Mass SMS</h1>
<form method="post" action="{{ url_for('send_sms') }}">
<div class="form-group">
<label for="message">Message</label>
<textarea class="form-control" id="message" name="message" rows="3" required></textarea>
</div>
<div class="form-group">
<label>Select Groups</label>
<!-- Groups -->
</div>
<button type="submit" class="btn btn-primary">Send SMS</button>
</form>
</div>
I was using the live server provided by the VS Code live server extension I believe. When I clicked on submit for my form, I received a 405 Error. When I look at the network section in developer tools, the Response Headers has a row stating which methods are allowed and only GET, HEAD, OPTIONS
are allowed. I tried other solutions people had proposed on SO such as:
- Adding the following to
web.config
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>
- Defining the methods before the
index()
function
@app.route('/', methods=['GET','POST'])
def index():
return render_template('index.html')
-
Checking the handler mappings to see if
POST
is part of their allowed Verbs -
Adding
GET
to the methods forsend_sms()
app.route('/send_sms',methods=['GET','POST'])
def send_sms():
I am really confused on what to do. I used to have this error when learning HTML Forms and php but I brushed it off as I didn’t have a dedicated web server. However this seems to be a problem with the methods in general. Appreciate the help.