def post(self): username = self.request.POST['username'] correct_password = user_dict[username] password = self.request.POST['password'] if (correct_password == None or correct_password != password): # error page! t = jinja_env.get_template('failure_login.html') self.response.write(t.render()) else: t = jinja_env.get_template('success_login.html') self.response.write(t.render())
def get(self): student_name = self.request.GET['student'] if student_name == "": t = jinja_env.get_template('quiz_home.html') self.response.write( t.render(topic_error="Please enter your name.")) elif 'topic' not in self.request.GET: t = jinja_env.get_template('quiz_home.html') student_name = self.request.GET['student'] self.response.write( t.render(name_error="Please select a quiz topic.", student_name=student_name)) else: student_name = self.request.GET['student'] topic = self.request.GET['topic'] # not sure if this is going to work... but we'll try it! topic_test = topic_mapping[topic] t = jinja_env.get_template('quiz.html') self.response.write( t.render(student=student_name, topic=topic, test=topic_test))
def get(self): """ Writing without specifying content type... """ """ self.response.write('Hello World') """ """ Writing with content type specification as html """ """ self.response.headers['Content-Type'] = 'text/html' self.response.write('Hello World, this is Ash on a testpage!') """ """ Writing by using the templating engine to render a template """ t = jinja_env.get_template('test.html') self.response.write(t.render())
def post(self): student_name = self.request.POST['student'] topic = self.request.POST['topic'] topic_test = topic_mapping[topic] num_questions = len(topic_test) num_correct = 0 for question in topic_test: student_ans = self.request.POST[question[1]] if (student_ans == question[6]): num_correct = num_correct + 1 passed = False result_msg = "" if (num_correct / float(num_questions) > 0.5): passed = True result_msg = "You passed the test!" else: passed = False result_msg = "You failed the test. Maybe you need more practice?" t = jinja_env.get_template('quiz_result.html') self.response.write( t.render(student=student_name, topic=topic, num_correct=str(num_correct), num_questions=str(num_questions), result_msg=result_msg)) email_msg = "Student: " + student_name + " did a test on: " + topic + ". " email_msg = email_msg + "their score was: " + str( num_correct) + "/" + str(num_questions) + "." mail.send_mail(sender="Aishwary Gupta <*****@*****.**>", to="Aishwary Gupta <*****@*****.**>", subject="Quiz Results", body=email_msg)
def get(self): #self.response.headers['Content-Type'] = 'text/plain' #self.response.write('Hello World, this is Ash!') t = jinja_env.get_template('login.html') self.response.write(t.render())
def post(self): t = jinja_env.get_template('test_post.html') self.response.write(t.render())
def get(self): t = jinja_env.get_template('quiz_home.html') self.response.write(t.render())