如何服务于AppFog与Apache静态内容(WSGI Python应用程序) [英] How to serve static content with Apache in AppFog (WSGI Python app)

查看:246
本文介绍了如何服务于AppFog与Apache静态内容(WSGI Python应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 AppFog PaaS的系统了几天,我喜欢它,它可能是最好的PaaS我已经测试过系统(我使用的其他3那些previously),但没有发现有关如何在前端提供静态内容与Web服务器(Apache HTTPS或nginx的)信息,我不知道是什么正在使用服务器

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.

我的应用程序是一个Python WSGI与CherryPy的和AppFog完美的作品,但我不wan't的CherryPy提供静态内容,我认为阿帕奇的httpd或nginx的是一个更好的选择。

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.

推荐答案

通过瑞安的支持下,我终于能够加载静态文件!具体操作步骤如下:

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


  1. 在项目中创建根静态目录 - 在这里所有的静态文件将被收集运行的 collectstatic 命令。

编辑的 settings.py 的文件:

STATIC_ROOT = os.path.join(os.path.abspath是(os.path.dirname(文件)),'../static')#可根据您的设​​置来改变。 PY文件!

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_URL = '/static/'

添加以下在 URL模式变线的 urls.py 的文件:

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

URL(R'^静态/(P *)$?','django.views.static.serve',{'DOCUMENT_ROOT':settings.STATIC_ROOT})

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

最后,在本机上运行collectstatic命令。

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

蟒蛇manage.py collectstatic

python manage.py collectstatic

就是这样。推入AF:)

That's it. Push in AF :)

缺点:需要运行 collectstatic 每次我们有一个新的静态文件的时间...

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

这篇关于如何服务于AppFog与Apache静态内容(WSGI Python应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆