I am trying to send email via my server to the persons who have done their registration. Their information is getting stored in database( csv file) but when I click on submit button, nothing loads and "Problem loading page" is shown. This is the part of the code of applications.py implemented by me`import cs50

import csv
import os
import smtplib

from flask import Flask, jsonify, redirect, render_template, request

# Configure application
app = Flask(__name__)

# Reload templates when they are changed
app.config["TEMPLATES_AUTO_RELOAD"] = True

def after_request(response):
    """Disable caching"""
    response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
    response.headers["Expires"] = 0
    response.headers["Pragma"] = "no-cache"
    return response

@app.route("/", methods=["GET"])
def get_index():
    return redirect("/form")

@app.route("/form", methods=["GET"])
def get_form():
    return render_template("form.html")

@app.route("/form", methods=["POST"])
def post_form():
    if not request.form.get("name") or not request.form.get("eid") or not request.form.get("year") or not request.form.get("club"):
        return render_template("error.html", message="Error dude")
    file = open("survey.csv", "a")
    writer = csv.writer(file)
    writer.writerow((request.form.get("name"), request.form.get("eid"),request.form.get("year"), request.form.get("club")))

    email = request.form.get("eid")
    message = "You are registered!"
    server = smtplib.SMTP('smtp.gmail.com',587)
    server.login("nagharshu16@gmail.com", "********")
    server.sendmail("nagharshu16@gmail.com", email, message)
    return redirect("/sheet")

@app.route("/sheet", methods=["GET"])
def get_sheet():
    file = open("survey.csv", "r")
    reader = csv.reader(file)
    students = list(reader)
    return render_template("registered.html", students=students)
  • I'm getting the same error trying to reconstruct the example from the lecture. #... @app.route("/register", methods=["POST"]) def register(): name = request.form.get("name") email = request.form.get("email") dorm = request.form.get("dorm") if not name or not dorm: return render_template("failure.html") message = "You are registered!" server = smtplib.SMTP("smtp.gmail.com", 587) server.starttls() server.login(os.getenv('U'), os.getenv('P')) server.sendmail(os.getenv('U'), email, message) return render_template("success.html") – bor999 Aug 4 '19 at 8:01

You must log in to answer this question.

Browse other questions tagged .