This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{%extends "templateinheritance.html" %} | |
{% block header %} | |
<table border="1"> | |
<tr> | |
<td>Article2</td> | |
<td>Author2</td> | |
</tr> | |
{% end %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
import time | |
class ItWorks(tornado.web.RequestHandler): | |
def get(self): | |
self.write("It Works!!") | |
class Article(tornado.web.RequestHandler): | |
def get(self,id): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
class Hello(tornado.web.RequestHandler): | |
def get(self): | |
self.write("Hello, world") | |
class User(tornado.web.RequestHandler): | |
def get(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import httplib2 | |
h = httplib2.Http() | |
response, content = h.request("http://127.0.0.1:8888/user/", "GET") | |
print"HTTP GET request" | |
print "Reponse:", response, "\nContent:", content, "\nCookie:", response['set-cookie'] | |
## Resending the request with cookie with headers | |
headers = {"Cookie":response['set-cookie']} | |
response_2, content_2 = h.request("http://127.0.0.1:8888/user/", "GET", headers = headers) | |
print "\nResending the request with cookie in headers" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html>{{ name }}</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
class Main(tornado.web.RequestHandler): | |
def get_current_user(self): | |
return self.get_secure_cookie("user") | |
def get(self): | |
if not self.current_user: | |
self.redirect("/login") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
class Main(tornado.web.RequestHandler): | |
def get_current_user(self): | |
return self.get_secure_cookie("user") | |
@tornado.web.authenticated | |
def get(self): | |
## This work is achieved by decorator @tornado.web.authenticated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
import tornado.websocket | |
class Socket(tornado.websocket.WebSocketHandler): | |
def open(self): | |
print "Socket opened" | |
def on_message(self, message): | |
self.write_message("Msg is " + message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
import httplib2 | |
httplib2.debuglevel=1 | |
http = httplib2.Http() | |
class AsyncHandler(tornado.web.RequestHandler): | |
@tornado.web.asynchronous | |
def get(self): |