只读文件系统:"/srv/media/house_preview/question_4.PNG"



我有一个简单的Django应用程序部署到App Engine,它连接到Cloud SQL(PostgreSQL)实例。这个 Django 应用程序允许用户登录/注册并出售物品。登录/注册工作正常,但是在出售待售物品时出现以下错误:

Request Method: POST
Django Version: 3.0.3
Python Version: 3.7.7
Installed Applications:
['projects',
'blog',
'users.apps.UsersConfig',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback (most recent call last):
File "/env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/env/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/env/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/srv/projects/views.py", line 28, in createListing
link.save()
File "/srv/projects/models.py", line 24, in save
super(Listing_Database, self).save(*args, **kwargs)
File "/env/lib/python3.7/site-packages/django/db/models/base.py", line 746, in save
force_update=force_update, update_fields=update_fields)
File "/env/lib/python3.7/site-packages/django/db/models/base.py", line 784, in save_base
force_update, using, update_fields,
File "/env/lib/python3.7/site-packages/django/db/models/base.py", line 887, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/env/lib/python3.7/site-packages/django/db/models/base.py", line 926, in _do_insert
using=using, raw=raw,
File "/env/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/env/lib/python3.7/site-packages/django/db/models/query.py", line 1204, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1383, in execute_sql
for sql, params in self.as_sql():
File "/env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1328, in as_sql
for obj in self.query.objs
File "/env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1328, in <listcomp>
for obj in self.query.objs
File "/env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1327, in <listcomp>
[self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
File "/env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1278, in pre_save_val
return field.pre_save(obj, add=True)
File "/env/lib/python3.7/site-packages/django/db/models/fields/files.py", line 288, in pre_save
file.save(file.name, file.file, save=False)
File "/env/lib/python3.7/site-packages/django/db/models/fields/files.py", line 87, in save
self.name = self.storage.save(name, content, max_length=self.field.max_length)
File "/env/lib/python3.7/site-packages/django/core/files/storage.py", line 52, in save
return self._save(name, content)
File "/env/lib/python3.7/site-packages/django/core/files/storage.py", line 267, in _save
fd = os.open(full_path, self.OS_OPEN_FLAGS, 0o666)
Exception Type: OSError at /projects/createListing
Exception Value: [Errno 30] Read-only file system: '/srv/media/house_preview/question_4.PNG'

我很确定这与图像上传有关。

不允许写入 Google App Engine 实例, 如果你想要谷歌领域的所有内容,你应该使用谷歌云存储

编辑您的代码以支持不同的 Google 云存储后端 ->例如使用 django-storage

除了/tmp目录外,无法在Google App Engine Standard Python3环境中写入文件。正如 Python3 GAE 官方文档中所述:

运行时包括一个完整的文件系统。文件系统是只读的,但位置/tmp除外,位置 是存储在 App Engine 实例 RAM 中的数据的虚拟磁盘。

相关内容

  • 没有找到相关文章

最新更新