我正在尝试按照本指南https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/
将带有静态文件的django应用程序部署到AWS EB我有标准的文件夹结构,项目和应用程序设置。我正在使用sqlite,因此不需要在AWS上设置数据库。我的python.config文件看起来像这样
container_commands:
01_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "myappproject.settings"
"PYTHONPATH": "/opt/python/current/app/myappproject:$PYTHONPATH"
"ALLOWED_HOSTS": "myappawseb.eu-central-1.elasticbeanstalk.com/"
"aws:elasticbeanstalk:container:python":
WSGIPath: "myappproject/wsgi.py"
NumProcesses: 3
NumThreads: 20
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
我以前做过pip冻结并在项目文件夹中有我的requirements.txt文件。
一切按计划在localhost上运行。在eb部署之后,我的静态文件无法正确加载。在我的settings.py中,我定义了STATIC_URL和STATIC_ROOT:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "..", "www", "static")
我的eb错误日志如下所示:
[Fri Oct 27 14:02:35.716529 2017] [:error] [pid 4533] for pattern in self.url_patterns:
[Fri Oct 27 14:02:35.716531 2017] [:error] [pid 4533] File "/opt/python/run/venv/lib/python3.4/site-packages/django/utils/functional.py", line 35, in __get__
[Fri Oct 27 14:02:35.716533 2017] [:error] [pid 4533] res = instance.__dict__[self.name] = self.func(instance)
[Fri Oct 27 14:02:35.716534 2017] [:error] [pid 4533] File "/opt/python/run/venv/lib/python3.4/site-packages/django/urls/resolvers.py", line 405, in url_patterns
[Fri Oct 27 14:02:35.716536 2017] [:error] [pid 4533] patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) [Fri Oct 27 14:02:35.716546 2017] [:error] [pid 4533] File "/opt/python/run/venv/lib/python3.4/site-packages/django/utils/functional.py", line 35, in __get__ [Fri Oct 27 14:02:35.716553 2017] [:error] [pid 4533] res = instance.__dict__[self.name] = self.func(instance) [Fri Oct 27 14:02:35.716554 2017] [:error] [pid 4533] File "/opt/python/run/venv/lib/python3.4/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
[Fri Oct 27 14:02:35.716556 2017] [:error] [pid 4533] return import_module(self.urlconf_name)
[Fri Oct 27 14:02:35.716558 2017] [:error] [pid 4533] File "/opt/python/run/baselinenv/lib64/python3.4/importlib/__init__.py", line 109, in import_module
[Fri Oct 27 14:02:35.716560 2017] [:error] [pid 4533] return _bootstrap._gcd_import(name[level:], package, level)
[Fri Oct 27 14:02:35.716562 2017] [:error] [pid 4533] File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
[Fri Oct 27 14:02:35.716563 2017] [:error] [pid 4533] File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
[Fri Oct 27 14:02:35.716565 2017] [:error] [pid 4533] File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
[Fri Oct 27 14:02:35.716567 2017] [:error] [pid 4533] File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
[Fri Oct 27 14:02:35.716568 2017] [:error] [pid 4533] File "<frozen importlib._bootstrap>", line 1129, in _exec
[Fri Oct 27 14:02:35.716570 2017] [:error] [pid 4533] File "<frozen importlib._bootstrap>", line 1471, in exec_module
[Fri Oct 27 14:02:35.716572 2017] [:error] [pid 4533] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
答案 0 :(得分:0)
最终修复它的是将settings.py中的静态根改为
STATIC_ROOT = os.path.join(BASE_DIR, "static")