Django + Pydev/Eclipse + Google App Engine - possible? - django

Has anyone been able to get Google App Engine/Django working in Pydev/Eclipse? I tried this but had difficulty getting Pydev to recognize all of the externally linked folders (django plugins) that I was referencing. I ended up copying all of those folders into the project en masse, rather than referencing them, resulting in a massively bloated project folder - it was really an unworkable solution that eventually made me give up the whole project. So, I'm wondering if anyone has tried this or has any idea what I might have been doing wrong. (Keep in mind this was my first attempt at using Pydev, Django, App Engine and Python!!)

I haven't personally set it up but i did see this tutorial on how to do it:
http://code.google.com/appengine/articles/eclipse.html

Pydev 1.4.6 (still only available in the nightly builds) has some special support to easy in the configuration. See: http://pydev.blogspot.com/2009/05/testing-on-pydev-146-google-app-engine.html

This tutorial shows how to configure Aptana (with PyDev installed) to be your coding and debugging platform for AppEngine. Similarly you can add Django libraries to Aptana too.
http://www.alishabdar.com/2009/05/06/develop-google-appengine-with-aptana-studio/

This question hasn't been replied to for some time and things have changed, so I thought I would provide and update.
PyDev now includes a Google App Engine configuration out of the box and you can debug and run GAE projects out of the box, this includes Django.
Just install GAE and the latest Eclipse/PyDev on your machine then create a GAE project and point PyDev at your versions of Python and Google App Engine.

appengine 1.31
Django 1.1
pydev 1.5.4
OS Ubuntu 9.10
eclipse .pydevproject file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_variables_property name="org.python.pydev.PROJECT_VARIABLE_SUBSTITUTION">
<key>GOOGLE_APP_ENGINE</key>
<value>/home/elvis/google_appengine</value>
</pydev_variables_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/pythonleggo</path>
</pydev_pathproperty>
<pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
<path>${GOOGLE_APP_ENGINE}</path>
<path>${GOOGLE_APP_ENGINE}/lib/webob</path>
<path>${GOOGLE_APP_ENGINE}/lib/yaml/lib</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
</pydev_project>
Files:
eclipse project folder
- app.yaml
- index.yaml
- init.py
- main.py
- manage.py
- .project
- .pydevproject
- settings.py (unable to load)
- urls.py
main.py:
from google.appengine.dist import use_library
use_library('django', '1.1')
from django.conf import settings
settings.configure(
DEBUG=True,
TEMPLATE_DEBUG=True,
ROOT_URLCONF = 'urls',
PROJECT_NAME = 'pythonleggo',
SETTINGS_MODULE = '.settings',
ADMINS = ('elvis', 'elvis#gmail.com'),
LANGUAGE_CODE = 'en-us',
SITE_ID = 1,
USE_I18N = True,
MEDIA_ROOT = '',
MEDIA_URL = '',
ADMIN_MEDIA_PREFIX = '/media/',
SECRET_KEY = 'shhh',
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source'),
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware'),
TEMPLATE_DIRS=('/home/jmurphy/workspace/pythonleggo/templates'),
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites')
)
#os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
from google.appengine.ext.webapp import util
def main():
# Run Django via WSGI.
application = django.core.handlers.wsgi.WSGIHandler()
util.run_wsgi_app(application)
if __name__ == ' __main__':
main()
eclipse run:
/usr/bin/python2.6 -u /home/elvis/google_appengine/dev_appserver.py
The PYTHONPATH that will be used is:
/home/elvis/.eclipse/org.eclipse.platform_3.5.0_155965261/plugins/org.python.pydev_1.5.4.2010011921/PySrc/pydev_sitecustomize:/home/elvis/workspace/pythonleggo:/home/elvis/google_appengine:/home/elvis/google_appengine/lib/webob:/home/elvis/google_appengine/lib/yaml/lib:/usr/lib/pymodules/python2.6:/usr/lib/pymodules/python2.6/gtk-2.0:/usr/lib/python2.6:/usr/lib/python2.6/dist-packages:/usr/lib/python2.6/dist-packages/PIL:/usr/lib/python2.6/dist-packages/gst-0.10:/usr/lib/python2.6/dist-packages/gtk-2.0:/usr/lib/python2.6/lib-dynload:/usr/lib/python2.6/lib-old:/usr/lib/python2.6/lib-tk:/usr/lib/python2.6/plat-linux2:/usr/local/lib/python2.6/dist-packages
I could not get the settings file to load using os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' . It appeared to be stripped from the environ that django received. I used settings.configure which appeared to work correctly. At this point I only have the default django page loading in appspot.

I originally linked to this tutorial. Pydev now has Django support so this is probably less relevant. It may still be useful for figuring out how to make them all work together though. You could also try looking at this blog post.

I've just started with Python and the Google App Engine today. I think we both banged our heads against the same wall with external referencing.
I've tried deploying the google-app-engine-django project for my app. I've extracted everything and I have under my root the /appengine_django and /django folder.
I've added them as source folders, and I've added the /google_appengine/google folder as an external reference.
Normally, this all made sense to me. Each contained the __ init __.py module. Still, when I tried to ctr+click on any of the import statements it couldn't resolve the path to the modules.
Strikingly, you do not import the immediate folder that contains an __ init __.py. To properly reference packages you import the parent folder that contains the package duh! That also means that, since I didn't want to use a /src folder, the actual project folder should be added as a source reference to get the /appengine_django and /django to be recognized as source folders.
With that done, everything is running smoothly. I guess it's to show I have more reading up to do on Py.

Here is an other tutorial that might help.
The eclispe version might be a bit old but it should get you
far enough to get a working project.
http://django-appengine.com/contents
It has complete eclipse set up
http://django-appengine.com/post/37462709481/
http://www.mkyong.com/google-app-engine/google-app-engine-python-hello-world-example-using-eclipse/
It has complete gae set up
http://django-appengine.com/post/37615321945/
It has complete django set up
http://django-appengine.com/post/37628665099/
And then explains how to combine those two projects
into one gae project.
http://django-appengine.com/post/37778427717/
I hope this helps others who are just starting out

Related

App Configure - Module, not configured correctly? Help Divio

I'm using the Divio Platform to deploy a simple Django application and no matter i've done with this namespace, it's throwing an error.
I have tried adding an init.py file in the folder, as well as out of the folder and i'm quite confused to be honest as I can't think how else my application would work. I've even tried renaming the folder, adjusting in main urls but nothing seems to be working. I have already reviewed the pep420 to see if it would help, also django but I think the issue is more towards Divio as folder structure goes like this. Might I know this is the first time im using this platform.
urlpatterns = [
# Voyage application #
path('/app', include('app.urls')),
] + aldryn_addons.urls.patterns() + i18n_patterns(
# add your own i18n patterns here
*aldryn_addons.urls.i18n_patterns() # MUST be the last entry!
)
django.core.exceptions.ImproperlyConfigured: The app module <module 'app' (namespace)> has multiple filesystem locations (['/app/app', './app']); you must configure this app with an AppConfig subclass with a 'path' class attribute

Django. Mezzanine new project not importing all files

I wanted to start playing around with Django again (I'm not an expert in Python/Django, but I can make nice things work tho). I used Mezzanine once just to see how it worked. The 'mezzanine-project myproject' command worked like a charm as I had a nice small app running quickly. So, today I downloaded the new Mezzanine 1.3 along with Django 1.4.3 and all its dependencies (pillow, pytz, html5lib, etc) and tried to create another project so I could now work on it in a more consistent manner for personal purposes.
For my surprise, when I ran the server, I got lots of 404 errors pointing to missing /static/ files. Also, after creating the database (with manage.py createdb command), the only thing created was the static folder containing only the pictures of the predefined gallery that come along with Mezzanine. Also, there is no Log in or signup buttons as well.
I've tried making a clean install of all Python and its site-packages with the same result. I also tried copying/pasting the folders containing missing files from the /site-packages/mezzanine folder into my project, but the result was just reducing the number of 404 messages.
I've been doing an extensive research on this issue (with no luck but maybe because of the release being recent?) and even trying to contact someone on the Mezzanine IRC channel with no success.
I hope I'm not missing something silly. Do I have to change anything (note that I'm ok with the old mezzanine default settings) in my settings.py or in a specific file before running manage.py createdb command?
For the record: before running createdb, The only thing I edited was settings.py and changed the database parameters to make it work with my MySQL Server and commenting the local_settings configuration as I do not need it.
Some parameters that could be of help:
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, STATIC_URL.strip("/"))
By default, DEBUG is set to False in settings.py, and DEBUG is set to True in local_setting.py
Given that, if you just commented out importing local_settings.py, DEBUG would be False.
Django's development server won't serve static files when DEBUG is set to False, see the staticfiles section of the Django docs for more details.

How do I include a Django app in my PYTHONPATH?

I want to be able to import things from applications in my project without referring to my project name.
My folder structure is like so; I have a project called djangoproject1, and inside I have a folder called apps, and then I have my individual apps in that folder.
djangoproject1, apps, and all my applications have an empty "__init__.py" file in them.
In my settings.py file I have the following code:
import os
import sys
PROJECT_ROOT = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(PROJECT_ROOT, "apps"))
I've tried adding my apps to INSTALLED_APPS several ways:
'djangoproject1.apps.app1',
'djangoproject1.apps.app2',
or
'apps.app1',
'apps.app2',
or
'app1',
'app2',
but nothing works. Whenever I try to do:
from app1 import *
I got an unresolved import error. I'm using the latest versions of eclipse and django
Ok, so I got it to work by adding the apps folder to the PYTHONPATH through eclipse under Project Properties. Is this eclipse only though? I'm not sure how this will work when I try and deploy the site. What do you guys think?
The statement sys.path.insert(0, os.path.join(PROJECT_ROOT, "apps")) looks OK to me. Following this you only need to add app1 to INSTALLED_APPS and everything should work. But apparently they are not working.
Try the following: 1. Print your sys.path and verify that your project's app directory is in the list. 2. Double check that your have an __init__.py inside your apps folder.
Update
OK. Now can you fire up Django shell and try importing again? If it fails, please post the stack trace here.
You must include apps directory to PYTHONPATH. Be sure that in apps directory don't have __init__.py, because it become a package instead of "simple directory". Than, include in settings.py
app1, app2, app3
Use
from app1 import *

Setting up Django on Server with WSGI getting Import Error "Module named myproject.urls Not found"

So I have created a django site and I wanted to move it from my computer to my server. I set up Django on the server, and used the WSGI configuration. When I try to go to the home page I get an Import Error, It says that the module "myproject.urls" isn't found. It's a Django error, and it looks like it is getting the settings.py file and looking at the setting for ROOT_URLCONF and seeing the right urls file. I created this project with the usual django-admin.py startproject myproject and I just wanted to see if everything was configured correctly, but now I'm getting this error.
Any Suggestions?
Remove the "myproject" from "myproject.urls". Somehow WSGI addresses the settings as the root, so no need to refer to it again.
It sounds like myproject isn't on your path - what happens if you load up a python shell and run import myproject? If that works, what happens when you run import myproject.urls? If only the second import fails, there's a syntax error in your urls.py or one of the files it imports.
#Afrowave, you saved a huge headache - thank you from me too!
Further to this - I did a little more digging and wanted to avoid having to amend a dozen files in my app to account for loosing 'myproject.' and the start of every import.
Instead, I found if you do something like this -- you don't have to :)
ROOT = '/home/user/path_to_project_root' # In my case, also the dir that contains media, templates etc
APP_ROOT = '/home/user/path_to_django_project'
sys.path.append(ROOT)
sys.path.append(APP_ROOT)
os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings'
Hope this helps someone in future.

google app engine (python): ImportError no module named django

So I'm trying to use the django 1.1 template engine with the google app engine web app framework, from here. This is on Ubuntu Jaunty, I've made sure that the PYTHONPATH contains the location of Django-1.1.1 yet I'm getting this 'ImportError: No module named django' error when it tries to execute the use_library() line below. Again, could somebody help me? I'm stumped.
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.1')
Came up with the following solution:
Get django 1.1 and put it under your project root.
Add an empty file "non_gae_indicator" to your project root folder.
Add django and non_gae_indicator to your app.yaml skip_files element:
skip_files:
- ^(.*/)?app\.yaml
- ^(.*/)?app\.yml
- ^(.*/)?index\.yaml
- ^(.*/)?index\.yml
- ^(.*/)?#.*#
- ^(.*/)?.*~
- ^(.*/)?.*\.py[co]
- ^(.*/)?.*/RCS/.*
- ^(.*/)?\..*
- ^(.*/)?.*\.bak$
- ^django
- ^non_gae_indicator
Now we have a way to tell whether we are running under the GAE-sdk or live - since non_gae_indicator won't be available when we are live.
So in main.py you can do:
if not os.path.exists(os.path.abspath(os.path.dirname(__file__)) + '/non_gae_indicator'):
# GAE
from google.appengine.dist import use_library
use_library('django', '1.1')
else:
# Not GAE - Add our django package to the path
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)) + '/django')
You should run your local SDK server with the --allow_skipped_files flag (or else the skipped files will appear to not be exist when checking them - the server console gives a warning about it).
#stallarida - The problem is that .96 is shipped as default with the SDK. What I did in the end, which is a dirty hack but works, is to update the version of django in the appengine directory to 1.1. Worked fine, needed a bit of tweaking between dev and production.
Specifically I had to comment out use_library('django', '1.1') when running locally but include it when uploading my app.
I'm sure there's a better solution and I'll work it out when my linux experience improves.