I am quite new to web development. I am trying to make a website using Flask and HTML. One of the webpages on the website is a contact page, where the user types out a message in a message box and sends it as an email to me, using flask_mail. However, when I press the Submit button to send the message, there is a ConnectionRefusedError. I really don't know what to do.
`ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.
You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:
dump() shows all variables in the frame
dump(obj) dumps all that's known about the object`
I have tried turning off my firewall, setting the port to some random number, changing the server to various things (the IP address, to 0.0.0.0, to an empty string...) - none of these worked.
Can anyone help please?
Here is the function that leads to the contact page:
`
@app.route('/contact/<username>/', methods=['GET', 'POST'])
def contact_page(username):
if request.method == 'POST':
person = request.form.get('name')
email = request.form['email']
subject = request.form.get('subject')
message = request.form.get('message')
email_message = Message(subject=subject,
recipients=app.config['MAIL_USERNAME'],
sender=email,
body=message)
mail.send(email_message)
flash(f"{person.title()}, you're email was submitted successfully.")
else:
pass
return render_template('contact.html', username=username)`
Here is the HTML contact page:
`
<form method="POST">
<div class="mt-4 mb-4">
<label for="name"> <b> Name: </b> </label>
<br>
<input id="name" type="text" name="name" placeholder="Name" required>
</div>
<div class="mt-4 mb-4">
<label id="email"> <b> Email Address: </b> </label>
<br>
<input type="email" name="email" placeholder="Email" required>
</div>
<div class="mt-4 mb-4">
<label id="subject" for="subject"> <b> Subject: </b> </label>
<br>
<div>
<input id="option1" value="option1" type="radio" name="Radio">
<label> Artwork </label>
<br>
<input id="option2" type="radio" value="option2" name="Radio">
<label> Random Comment </label>
<br>
<input id="option3" type="radio" value="option3" name="Radio">
<label> Other </label>
</div>
</div>
<div class="mt-4 mb-4">
<label> <b>Write your message: </b> </label>
<br>
<textarea id="message" placeholder="Tell me something..." rows="8" cols="60" required> </textarea>
</div>
<div>
</div>
<div class="alert alert-success mb-4">
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
<p> {{ message }} </p>
{% endfor %}
{% endif %}
{% endwith %}
</div>
<button type="submit" class="mb-4"> Submit </button>`