我正在尝试按照Heroku的建议通过WhiteNoise提供静态文件.当我在我的开发环境中运行时,会发生这种情况:collectstatic
Post-processing 'css/iconic/open-iconic-bootstrap.css' failed!
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle_noargs
collected = self.collect()
File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 120, in collect
raise processed
File "/home/Pieter/.virtualenvs/radiant/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", …Run Code Online (Sandbox Code Playgroud) Django 500 Error当我DEBUG = False在Django中设置时,我看到了.我在用Django 1.5 and Python 2.7.我也包含ALLOWED_HOSTS在我的模板中.这是我的完整settings.py:
# Django settings for genalytics project.
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
import djcelery
import os
__file__ = os.getcwd()
ROOT_PATH = os.path.dirname(__file__)
djcelery.setup_loader()
#New in Django 1.5
ALLOWED_HOSTS = ['localhost', '127.0.0.1:8000']
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('sachit', 'sachit.adhikari@zurelsoft.com')
)
BROKER_TRANSPORT = "sqlalchemy"
BROKER_URL = "sqla+mysql://root:password@localhost/galaxy"
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. …Run Code Online (Sandbox Code Playgroud) DEBUG在 Django 应用程序的 settings.py 文件中切换设置之间的功能差异究竟是什么?
我一开始以为DEBUG=True只是打开了 Django 的日志记录功能和中间件来报告错误,但现在我意识到我太天真了。了解 Django 内部系统在两种布尔设置下的工作方式有何不同,有助于在处理难以调试的普通状态 500 错误时形成假设
几个月来,我一直在努力在 Heroku 上部署我的第一个 Django 站点。我使用 成功构建git push heroku master并成功收集静态文件heroku run python manage.py collectstatic --noinput,但是当DEBUG = config('DEBUG', default=False, cast=bool). 当 DEBUG 设置为 True 时,该站点确实可以工作(尽管我将不得不弄清楚使数据库工作)。我认为我允许的主机设置正确。我可以在 SO 上找到的所有答案都不能完全解决我的问题。
我从这个答案中添加了日志记录,这在日志中为我提供了更多信息,但是我不明白为什么当我能够成功收集静态文件时它们不可用?
2018-12-09T16:24:38.181428+00:00 heroku[web.1]: State changed from starting to up
2018-12-09T16:24:39.173376+00:00 app[web.1]: /app/.heroku/python/lib/python2.7/site-packages/whitenoise/base.py:104: UserWarning: No directory at: /app/staticfiles/
2018-12-09T16:24:39.173419+00:00 app[web.1]: warnings.warn(u'No directory at: {}'.format(root))
2018-12-09T16:24:39.173421+00:00 app[web.1]: /app/.heroku/python/lib/python2.7/site-packages/whitenoise/base.py:104: UserWarning: No directory at: /app/staticfiles/
2018-12-09T16:24:39.173423+00:00 app[web.1]: warnings.warn(u'No directory at: {}'.format(root))
Run Code Online (Sandbox Code Playgroud)
我显然错过了很多,任何指导将不胜感激。
编辑添加:
import os
import dj_database_url
from …Run Code Online (Sandbox Code Playgroud) 我一直在开发一个在根/登陆页面中使用i18n/locale作为url前缀的应用程序.我尝试早期部署我的应用程序以进行测试,DEBUG = True,一切都运行良好.如果尝试访问domain.com,则会重定向到domain.com/en/
现在,因为我禁用了DEBUG = False,它不会重定向到/ en /,而是会显示404错误.
我看到了这个问题,这与我的情景很接近
Django 1.4 LocaleMiddleware不能与Apache一起使用,但可以与runserver一起使用
但是,对于我的情况,我已经有404页面设置及其处理程序和404.html文件.
以下是我的代码
settings.py
LANGUAGE_CODE = 'en-us'
ADMIN_LANGUAGE_CODE = LANGUAGE_CODE
gettext = lambda s: s
LANGUAGES = (
('ar', gettext('Arabic')),
('en', gettext('English')),
)
USE_I18N = True
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'apps.accounts.middleware.AccountSocialAuthExceptionMiddleware',
'apps.core.middleware.DefaultSiteMiddleware',
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.request",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
# custom context processors
"snowflake.apps.core.context_processors.project_name",
"snowflake.apps.core.context_processors.sites",
) …Run Code Online (Sandbox Code Playgroud) 我知道这个问题已经讨论过了.但问题仍然存在,我没有任何解决方案.请帮忙.
我的平台是:Ubuntu 14.04 LTS,Python 3.4,MySQL 5.5,Django 1.7,Nginx 1.4.6和Gunicorn 19.1.1.
当我DEBUG = False在生产服务器中设置时,我的Django应用程序运行可能会持续半天.在那之后,烦人Server Error (500)总是出现在某些功能上,但不是每一个.如果我转身DEBUG = True,一切都会好的.
我也定了ALLOWED_HOSTS = ['*'].有人说它不应该是生产中的外卡.但我的应用程序是公开的,我应该如何设置它?其他人说它应该是'localhost'.但只能localhost访问服务器?为什么要去生产呢?
这个问题有标准解决方案吗?谢谢.
django ×6
python ×2
django-1.5 ×1
exception ×1
heroku ×1
python-3.x ×1
static-files ×1
templates ×1