title: Module 'main' has no attribute application -- Google App Engine Python with Django
body: <p>I have been running into this problem for a short while now and simply can't find a solution anywhere. I am using Google App Engine to run a default Python 2.7 app with Django 1.5 (via GAE SDK) created through PyCharm. I can upload the app successfully, but upon visiting the actual page, I get a Server Error. Then, checking the logs in Google App Engine, I see this:</p>
  
  <pre><code>ImportError: &lt;module 'main' from '/base/data/home/apps/s~eloquent-ratio-109701/1.388053784931450315/main.pyc'&gt; has no attribute application
  </code></pre>
  
  <p>After searching the internet for a while, I was able to find a few posts which address this issue, but attempting them never seemed to solve my problem. For example: <a href="https://stackoverflow.com/questions/10056861/cannot-run-a-simple-helloworld-in-gae-python-2-7">This</a> problem was solved by replacing "application" with "app" in the following lines:</p>
  
  <pre><code>application = django.core.handlers.wsgi.WSGIHandler()
  util.run_wsgi_app(application)
  </code></pre>
  
  <p>In fact, I had run into this same issue before and this solution provided a fix for me in the past, however at that time I was running a separate app and it was not through the GAE.</p>
  
  <p>I checked the Django documentation for version 1.5 <a href="https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/" rel="nofollow noreferrer">here</a>, but the code and suggestions there don't seem to conflict with what I currently have in my project.</p>
  
  <p>I read a bit more about this type of problem, and saw another post that suggested checking the app's wsgi.py file to ensure that it is named 'application' or 'app' respectively, so that one could then use that same name throughout the rest of the application. However, upon checking those settings I saw that 'application' was used there too:</p>
  
  <pre><code>from django.core.wsgi import get_wsgi_application
  application = get_wsgi_application()
  </code></pre>
  
  <p>There's even a line in settings.py which uses the same nomenclature to declare the WSGI application:</p>
  
  <pre><code>WSGI_APPLICATION = 'Chimera.wsgi.application'
  </code></pre>
  
  <p>I'm really having trouble debugging this. I get the feeling it's really dumb and I just can't see it, but unfortunately I'm not particularly good at this kind of stuff -- I'm still a bit of a novice in this field.</p>
  
  <p>Does anyone have any idea what I could try in an attempt to fix this issue?</p>
  
  <p>UPDATE: I started making line by line changes and testing things, and eventually I found that the GAE log changes depending on the input for the "script" under app.yaml. So if I change the script under "handlers" between "main.app" and "main.application", it adjusts the log output to refer to "app" or "application" respectively. So that line in the app.yaml file tells the app what to look for, but I'm still not seeing why it can't be found. Not sure what else I could change to test it out. I wish I knew a bit more about the actual inner workings so that I could figure out why the app is confused about the attribute. Is it trying to run before it even gets instantiated or something?</p>
  
  <p>Source code below:</p>
  
  <p>main.py</p>
  
  <pre><code>import os, sys
  
  os.environ['DJANGO_SETTINGS_MODULE'] = 'Chimera.settings'
  
  from google.appengine.ext.webapp import util
  
  from django.conf import settings
  
  settings._target = None
  
  import django.core.handlers.wsgi
  import django.core.signals
  import django.db
  import django.dispatch.dispatcher
  
  def main():
      application = django.core.handlers.wsgi.WSGIHandler()
  
      util.run_wsgi_app(application)
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>app.yaml</p>
  
  <pre><code>application: eloquent-ratio-109701
  version: 1
  runtime: python27
  api_version: 1
  threadsafe: true
  
  handlers:
  - url: /.*
    script: main.application
  
  libraries:
  - name: django
    version: 1.5
  </code></pre>
  
  <p>wsgi.py</p>
  
  <pre><code>import os
  
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Chimera.settings")
  
  from django.core.wsgi import get_wsgi_application
  application = get_wsgi_application()
  </code></pre>
  
  <p>Full log from GAE:</p>
  
  <pre><code>Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
  handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
    File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 302, in _LoadHandler
  raise err
  ImportError: &lt;module 'main' from '/base/data/home/apps/s~eloquent-ratio-109701/1.388053784931450315/main.pyc'&gt; has no attribute application
  </code></pre>
  
  <p>Thanks for helping me out.</p>