简体   繁体   中英

Starting Django on a Linux server

Ok, i have created a nice Django app on my server

Obvioulsy I could do ./managy.py runserver 0:8000

But that's not really robust enough for production. I have constructed this code to start it

def server(application, port):
    """
    Application is the FLASK application object
    """
    from twisted.internet import reactor
    from twisted.web.server import Site
    from twisted.web.wsgi import WSGIResource

    resource = WSGIResource(reactor, reactor.getThreadPool(), application)
    site = Site(resource)

    reactor.listenTCP(port, site, interface="0.0.0.0")
    reactor.run()


if __name__ == '__main__':
    from oms.wsgi import application
    server(application, 8100)

I should also show the oms.wsgi file:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "oms.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

This seems work on (on a different port) but the problem is that all fancy formatting is gone. What's the recommended way to start server in a production environment?

If you're interested in something production worthy I would suggest using django with uWSGI/nginx. Here are the docs for getting started . After you're done hooking up uwsgi you can utilize nginx

You didn't need to write that first file. Instead,

twistd -n web --wsgi oms.wsgi.application

I'd recommend to use Nginx + UWSGi in your production environment. It's one of the best performance firendly combination that is easy to setup and manage. That's what they use at Disqus . Now try to imagine how much request they get each day... It must be pretty stable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM