Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make google app engine to support django's ImageField?

Currently I'm working on a django app which runs on the top of google app engine. One of a field of model looks like,

picture = models.ImageField()

But it shows the below error while saving that particular model

  File "/django_projects/cityguide-backend/src/lib/django/db/models/fields/files.py", line 93, in save
    self.name = self.storage.save(name, content, max_length=self.field.max_length)
  File "/django_projects/cityguide-backend/src/lib/django/core/files/storage.py", line 63, in save
    name = self._save(name, content)
  File "/django_projects/cityguide-backend/src/lib/django/core/files/storage.py", line 248, in _save
    fd = os.open(full_path, flags, 0o666)
  File "/google_appengine/google/appengine/tools/devappserver2/python/stubs.py", line 73, in fake_open
    raise OSError(errno.EROFS, 'Read-only file system', filename)
OSError: [Errno 30] Read-only file system: u'/django_projects/backend/src/Screenshot_from_2014-04-18_190527.png'

After some researches I found that, GAE won't support writing operations to file system . Think I need to use GAE's blobstore or Google Cloud storage. But I don't know how to integrate these with the django's model.

like image 378
Avinash Raj Avatar asked Jan 26 '16 04:01

Avinash Raj


People also ask

Can I use Django with App Engine standard?

This tutorial uses Django 4, which requires at least Python 3.8. App Engine standard supports Python 3.7 and higher, including Python 3.8. App Engine standard supports . In this tutorial, you will: Create and connect a Cloud SQL database. Create and use Secret Manager secret values. Deploy a Django app to App Engine standard.

How to create an app in Django with Geeks?

How to Create an App in Django ? Enter the following code into models.py file of geeks app. A new folder named migrations would be created in geeks directory with a file named 0001_initial.py Thus, an geeks_field ImageField is created when you run migrations on the project. It is a field to store valid image files. How to use ImageField ?

How do I enable API's in Google Django?

And this is the new Google Django tutorial home. You now need to click on API's and services. When in there, you do have the option to click Enable API's and services. But first off, we need to click on credentials we need to set up the API key click on click banjos.

What is the use of field name in Django?

It’s useful for documentation even if your field isn’t used on a form. A human-readable name for the field. If the verbose name isn’t given, Django will automatically create it using the field’s attribute name, converting underscores to spaces.


1 Answers

To be specific, Django doesn't support App Engine's Cloud Storage or Datastore by default and requires custom storage providers to work with them. These are the solutions which are covered by the official Google docs:

  • Django non-rel which supports App Engine Datastore. See also the related article in the Cloud Platform documentation.
  • If you prefer to use CloudSQL or an external MySQL database as a back-end, you can use the django.db.backends.mysql module as per this guide.

There are also the following unofficial projects:

  • Djangae, which is a newer project geared specifically towards App Engine Datastore.
  • The 'django-appengine-toolkit' supports Cloud Storage.

If you want to implement your own storage provider using Cloud Storage you can take a look at storage.py from django-appengine-toolkit as a reference.

like image 175
Adam Avatar answered Oct 11 '22 18:10

Adam