Serving static files with Twisted and Django in non-root folders

I am migrating an application ( Sage ) from Twisted to Django.

Currently static documentation is executed under /doc/static

, and real-time (embedded on the fly) documentation is executed under /doc/live

.

Can Twisted be used to serve only /doc/static

, leaving Django to serve the rest /doc/*

?

+2


source to share


3 answers


It can be done, the degree of elegance just changes ... I understand this is for the transition, so maybe it shouldn't be very pretty.

If you need Twisted to serve static files, you need to either hack django's proxy pass for those files, or throw something in front of it all. Also Perlbal with VPATH can do this, it will use the regex of URLs and force them to go to the right services.



If you don't need to use Twisted, there are many different ways to do this. You can still use Perlbal or something similar to serve up static files, which you need to end up with anyway.

+2


source


Check out this link on how to run Django on top of Twisted: (instructions copied from the blog)

  • easy_install Twisted
  • easy_install Django
  • Profit!
  • django-admin.py startproject foo
  • Create myapp.py with the following code:

    from django.core.handlers.wsgi import WSGIHandler

    application = WSGIHandler ()

  • export DJANGO_SETTINGS_MODULE = foo.settings

  • twistd -no web --wsgi = myapp.application

Further down the comments, there is also an example of how to serve media directly with Twisted prior to submitting the request to Django:



To handle media files, just use "static.File" from "twisted.web" like so: staticrsrc = static.File (os.path.join (os.path.abspath (")," myjjangosite / media ")), and then add this resource to your root resource eg: root.putChild ("media", staticrsrc)

Disclaimer: I haven't tried this myself, but the blog post seems to be quite recent and the author is ready to answer questions.

EDIT: There is another article written on this topic with instructions on how to get it to work here , which appears to include static static files with Twisted directly.

+3


source


If I didn't understand the question, why not just rewrite / doc / static url in Twisted before it even reaches Django (i.e. at the Apache / proxy level)?

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

-1


source