Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serve static content with Apache in AppFog (WSGI Python app)

I'm using AppFog PaaS system for a few days, and I love it, It's probably the best PaaS system that I've tested (I've used other 3 ones previously), but didn't find information about how to serve static content with the Web server in frontend (Apache https or nginx) I'm not sure what server is being used.

My app is a Python WSGI with CherryPy and works perfectly in AppFog but I don't wan't CherryPy to serve static content, I think that Apache httpd or nginx is a better option for that.

like image 886
Roberto Avatar asked Nov 03 '22 12:11

Roberto


1 Answers

With Ryan's support, I'm finally able to load static files! Here are the steps:

  1. Created a 'static' directory in the project root - here all static files will be collected running the collectstatic command.

  2. Edit the settings.py file:

    STATIC_ROOT = os.path.join( os.path.abspath( os.path.dirname(file) ), '../static' ) # May change depending on where your settings.py file is!

    STATIC_URL = '/static/'

  3. Add following line in urlpatterns variable in urls.py file:

    url(r'^static/(?P.*)$', 'django.views.static.serve', { 'document_root': settings.STATIC_ROOT} ) ,

  4. Finally, run collectstatic command in your local machine. This will copy all static files from the apps you are using:

    python manage.py collectstatic

That's it. Push in AF :)

Downside: Need to run collectstatic every time we have a new static file...

like image 65
Shafiul Avatar answered Nov 10 '22 07:11

Shafiul