I'm using Django along with appengine. When I try to save a record, I'm getting the error
"app_id must not be empty". The application name has been set in app.yaml. I also added
os.environ['APPLICATION_ID'] = 'test' in main.py. However, I continue to get the same error.
When I try to save a record, I'm getting the error "app_id must not be empty".
When I'm using appengine as "standalone" e.g. (unit testing) in order to fix the "app_id must not be empty" error I always execute:
app_id = 'XXXXXX'
os.environ['APPLICATION_ID'] = app_id
datastore_path = os.path.join(tempfile.gettempdir(),'dev_appserver.datastore')
history_path = os.path.join(tempfile.gettempdir(),'dev_appserver.datastore.history')
require_indexes = False
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
datastore = datastore_file_stub.DatastoreFileStub(app_id, datastore_path, history_path, require_indexes=require_indexes)
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', datastore)
just before my code that use the Google App Engine datastore.
If you run the appserver locally you shouldn't need this code because all the magic is made by the framework reading the app.yaml file
I haven't seen your error before. Note that you can't use the native Django database functions without using the "Django Helper" application:
http://code.google.com/appengine/articles/appengine_helper_for_django.html
You do not need to use Django Helper if you are only using parts of Django (but using native App Engine Models for storage):
http://code.google.com/appengine/docs/python/datastore/overview.html
Related
I followed a tutorial from a site and I deployed my django app on pythonanywhere.com.For this purpose I had to use git to upload codes.As a result my settings.py file was accessible by anybody.so any one could see my secret key on settings.py .It is not good right?
I also left DEBUG = True later I found it is not secure.Then I set DEBUG = False on my local machine and it showed it need allowed hosts.What are those things? what should I do? Where can I learn about these?
I'm following your setup from here https://github.com/dannymilsom/djangae-blog and I'm able to run static django pages on GAE without any issues. The problems start when I try to use "djangae.db.backends.appengine" as I want to have some basic data stored in DB. I basically don't know how to get my django models synced to the datastore in GAE. When I follow this doc here http://djangae.readthedocs.org/en/latest/sandbox/, I end up using "./manage.py --sandbox=remote makemigrations" but that gives me nasty error like this:
https://gist.github.com/sikor80/334241b17b44b94b95c5
and additionally when I try to sync my models locally and get this error https://gist.github.com/sikor80/879b5df7fd8ff6d42f88, my models are very simple as shown https://gist.github.com/sikor80/1c294b3339a2ff91c343
Would anybody know how to deal with it?
thanks!
Just a guess, the errors show an appid name of 'XXX'. You need to create that project through the Google cloud console first before you can use it as an app-id
I am new to Flask, i have three sections in config.py file
say
class Config(object):
DEBUG = False
TESTING = False
DATABASE_URI = 'sqlite://:memory:'
class ProductionConfig(Config):
DATABASE_URI = 'mysql://user#localhost/foo'
class DevelopmentConfig(Config):
DEBUG = True
class TestingConfig(Config):
TESTING = True
And as per documentation we can pass one the config at a time and run the app so the app will run for the passed config settings only.
I am looking changing the config based on url pattern,
so say if url is:
http://127.0.0.1:8080/api/app/hello should use app.config.from_object(ProductionConfig)
http://127.0.0.1:8080/api/app_dev/hello should use app.config.from_object(DevelopmentConfig)
http://127.0.0.1:8080/api/app_test/hello should use app.config.from_object(TestingConfig)
Is it possible while running app i want to change config based on url pattern so that i dont have to run multiple instance of app at time.
Please guide me how can i catch the url pattern in middleware to change configuration file.
It sounds like what you might be looking for is application dispatching, where each app is the same except for the configuration file that is loaded.
here is a solution for a very similar issue, except it uses subdomain dispatching rather than URL dispatching as you have requested.
The basic concept should apply, and taking this together with the examples in the first link should give you a good start for developing code that suits your needs.
You can do this inside a route endpoint
app.config['DEBUG'] = True
but it affects the whole app object. So when you GET /api/app_dev/hello and then /api/app/whatever; you are still using app_dev config.
In config file you can set API
_PATH. and in blueprint you need to set this parameter for required APIs
I am new to Google App Engine. I have deploy the pure django application in google app engine. It is working fine. But I wrote the django file upload functionality as shown below,
def forhandler(list, project_id, task_id, request):
for i in list:
filename = i
extension = filename.content_type
print i
newdoc = FileUpload(project_id=project_id, task_id=task_id, file=filename, filetype=extension)
newdoc.save()
When I run the ./manage.py runserver. The above functionality working correctly and uploading files correctly. When I use google app engine means dev_appserver.py my_project. It is perfect but when I upload the file using above functionality It gives an error as shown below,
Exception Value: [Errno 30] Read-only file system: u'/home/nyros/Desktop/projectstat/projectstat/media/documents/2013/05/24/1354676051_chasm_fishing_w1.jpeg'
How do I upload the file using django with google app Engine ? Please solve my problem.Thanks......
The problem here is that App Engine uses a read-only filesystem, and the default Django file upload mechanism wants to store files on disk. (Regardless of whether you're using App Engine or not, storing images in an ordinary database is a bad idea.)
Instead, you should use AppEngine's Blobstore API to save the image. This is special storage App Engine provides for storing large data uploaded by users.
The good news is there's a plugin that takes care of all of this for you: http://www.allbuttonspressed.com/projects/django-filetransfers
Just follow the instructions there and you should be in business.
(Note: I've only tried this with django-nonrel. I've never tried with with vanilla Django.)
The best way to upload files in google app engine with python is using the blobstorehandler.
class Upload(blobstore_handlers.BlobstoreUploadHandler):
for upload in self.get_uploads():
try:
img = Image()
img.primary_image = upload.key()
img.put()
except:
pass
I'm having trouble getting my Django project to work with a CouchDB database.
I'm running Python 2.6.6, Django 1.3, and Lion on a Mac
I've got Django, CouchDB, and CouchDBKit installed. I can import all of them from the python interpreter without a problem. If I go to my CouchDB database URL, I can see the db.
The problem is, when I try to go to my django project URL, I get the following error:
You haven't set the database ENGINE setting yet.
I have the following lines in my settings.py file:
COUCHDB_DATABASES = (
('my_project.my_db', 'http://127.0.0.1:5984/my_db'),
)
The only possible solution I've found so far, is to set a throwaway database in the normal database engine settings. But, this just throws another error, because Django starts looking for database tables in the throw away DB.
Edit with new info:
I'm accessing my DB via an SSH tunnel
I'm able to create and access a CouchDB from the python interpeter.
I've run a test from the python interpreter, to access the app DB (again, via the tunnel), and the returned data accurately.
It's just when I try to access the actual site from a browser URL, I get the engine not defined error.
Django seems to be trying to use a normal DB (which isn't setup), instead of the CouchDB.
Any ideas?