Last active
August 15, 2016 08:09
-
-
Save alexryabtsev/f02a6bf7b952cdfda3ccd239e2a44b09 to your computer and use it in GitHub Desktop.
Run Django application in CherryPy
This file contains hidden or 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
| ... | |
| if __name__ == '__main__': | |
| ... | |
| if len(sys.argv) > 1: | |
| # Django management commands | |
| if sys.argv[1] == 'manage': | |
| os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") | |
| from django.core.management import execute_from_command_line | |
| args = ['./manage.py'] + sys.argv[2:] | |
| execute_from_command_line(args) | |
| else: | |
| class IndexPage(object): | |
| @cherrypy.expose | |
| def index(self): | |
| return open(api_root('public', 'frontend', 'index.html')) | |
| cherrypy.tree.graft(application, "/backend") # Add main WSGI application | |
| cherrypy.tree.mount(IndexPage(), '/', {}) # Add client pages | |
| django_media_url = env('DJANGO_MEDIA_URL', default='/m/') | |
| django_static_url = env('DJANGO_STATIC_URL', default='/s/') | |
| cherrypy.tree.mount(None, '/static', {'/': { | |
| 'tools.staticdir.dir': api_root('public', 'frontend'), | |
| 'tools.staticdir.on': True, | |
| }}) # Add client static | |
| cherrypy.tree.mount(None, django_media_url[:-1], {'/': { | |
| 'tools.staticdir.dir': api_root('public', 'media'), | |
| 'tools.staticdir.on': True, | |
| }}) # Add Django media directory | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment