简体   繁体   English

在Heroku上使用django从dj-static切换到Amazon CDN

[英]Switching to Amazon CDN from dj-static with django on Heroku

I have been developing a django site on Heroku and using dj-static in my wsgi.py. 我一直在Heroku上开发django网站,并在wsgi.py中使用dj-static。 I am now about to move my site static files onto Amazon. 我现在要将站点静态文件移动到Amazon。 Do I need to now remove the references to dj-static from my wsgi.py file? 现在是否需要从wsgi.py文件中删除对dj-static的引用? I'm concerned about the following lines of code. 我担心以下代码行。 What would be the correct thing to do? 正确的做法是什么? Do they need to go? 他们需要走吗? If so, what do I put in their place?: 如果是这样,我该怎么放置它们?

from django.core.wsgi import get_wsgi_application
from dj_static import Cling

application = Cling(get_wsgi_application())

Thanks, 谢谢,

Euan uan

If you are serving files using django-storages you don't need to use dj-static anymore. 如果您正在使用django-storages提供文件,则无需再使用dj-static dj-static is only used when you want to serve the static files using a WSGI server like gunicorn . dj-static仅在您想使用像gunicorn这样的WSGI服务器提供静态文件时使用。 In your case you are using Amazon's servers. 在您的情况下,您正在使用Amazon的服务器。

To answer your question, you can revert to the default wsgi.py file which looks something like this: 要回答您的问题,您可以恢复为默认的wsgi.py文件,该文件如下所示:

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

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

You can also remove dj-static from your virtualenv and from requirements.txt 您还可以从virtualenvrequirements.txt删除dj-static

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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