Commits

Shu Zong Chen committed e97dd46

Initial project layout

  • Participants

Comments (0)

Files changed (9)

+# use glob syntax.
+syntax: glob
+
+*.swp
+*.local
+__pycache__
+[watcher:server]
+cmd = python server.py --fd=$(circus.sockets.server)
+copy_env = True
+use_sockets = True
+
+[socket:server]
+host = 127.0.0.1
+port = 8000

lovestory/__init__.py

+from .urls import urls
+from tornado_circus import Application
+
+class LoveStoryApp(Application):
+	def __init__(self, *args, **kwargs):
+		super().__init__(*args, **kwargs)
+		#self.db = models.DB()

lovestory/urls.py

+from . import views
+
+urls = [
+	(r"^/$", views.Test),
+]

lovestory/views.py

+from tornado.web import RequestHandler
+
+def require_login(f):
+	"""Decorator for methods that need authenticated user"""
+	def wrapped(self, *args, **kwargs):
+		if self.current_user is None:
+			self.redirect("/")
+		else:
+			return f(self, *args, **kwargs)
+	return wrapped
+
+class BaseView(RequestHandler):
+	def get_current_user(self):
+		return self.get_cookie("user")
+
+	def login(self, username):
+		self.set_cookie("user", username)
+		self.redirect("/chat")
+
+class Test(BaseView):
+	def get(self):
+		self.render("test.html")
+
+class Login(BaseView):
+	def get(self):
+		self.render("login.html")
+tornado
+circus
+tornado_circus
+#!/bin/bash
+circusd conf/circus.ini
+import os.path
+from tornado.options import parse_command_line
+from tornado import ioloop
+from tornado.web import StaticFileHandler
+import lovestory
+
+BASE_PATH = os.path.abspath(os.path.dirname(__file__))
+
+DEBUG = True
+
+class NoCacheStaticFileHandler(StaticFileHandler):
+	def set_extra_headers(self, path):
+		self.set_header("Cache-control", "no-cache")
+
+if DEBUG:
+	STATIC_HANDLER_CLASS = NoCacheStaticFileHandler
+else:
+	STATIC_HANDLER_CLASS = StaticFileHandler
+
+settings = {
+	"static_path": os.path.join(BASE_PATH, 'static'),
+	"static_handler_class": STATIC_HANDLER_CLASS,
+	"template_path": os.path.join(BASE_PATH, 'templates'),
+	"debug": DEBUG,
+}
+
+application = lovestory.LoveStoryApp(
+	lovestory.urls,
+	**settings
+)
+
+if __name__ == "__main__":
+	parse_command_line()
+	application.listen(None)
+	print ("server started!")
+	ioloop.IOLoop.instance().start()

templates/test.html

+<h1> Hello world </h1>