-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.py
56 lines (44 loc) · 1.49 KB
/
serve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import django
import webbrowser
from threading import Timer
import cherrypy
from django.conf import settings
from django.core.handlers.wsgi import WSGIHandler
class DjangoApplication(object):
HOST = "192.168.0.112"
PORT = 8001
def mount_static(self, url, root):
"""
:param url: Relative url
:param root: Path to static files root
"""
config = {
'tools.staticdir.on': True,
'tools.staticdir.dir': root,
'tools.expires.on': True,
'tools.expires.secs': 86400
}
cherrypy.tree.mount(None, url, {'/': config})
def open_browser(self):
Timer(3, webbrowser.open, ("http://%s:%s" % (self.HOST, self.PORT),)).start()
def run(self):
cherrypy.config.update({
'server.socket_host': self.HOST,
'server.socket_port': self.PORT,
'engine.autoreload_on': False,
'log.screen': True
})
self.mount_static(settings.STATIC_URL, settings.STATIC_ROOT)
cherrypy.log("Loading and serving Django application")
cherrypy.tree.graft(WSGIHandler())
cherrypy.engine.start()
self.open_browser()
cherrypy.engine.block()
if __name__ == "__main__":
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cs411_bookworm.settings')
django.setup()
print "Your app is running at http://50.148.113.36:8001"
DjangoApplication().run()