QuickNote: follow the Official guide may not be enough.
At first, I put ‘django’ in requirements.txt and put in the root dir of the DotCloud project, but it failed.
1 2 3 4 5 6 7 8 |
2011-07-22 XX:XX:XX [api] Waiting for the build. (It may take a few minutes) 2011-07-22 XX:XX:XX [www.0] The build started 2011-07-22 XX:XX:XX [www.0] Fetched code revision rsync-yyyyyyyyyy.y 2011-07-22 XX:XX:XX [www.0] Reloading nginx configuration: nginx. 2011-07-22 XX:XX:XX [www.0] uwsgi: stopped 2011-07-22 XX:XX:XX [www.0] uwsgi: started 2011-07-22 XX:XX:XX [www.0] The build finished successfully 2011-07-22 XX:XX:XX [api] Deploy finished |
And when I trace the log, it shows….
1 2 3 4 5 6 7 |
==> /var/log/supervisor/uwsgi.log <== added /home/dotcloud/current to pythonpath. interpreter for app 0 initialized. Traceback (most recent call last): File "/home/dotcloud/current/wsgi.py", line 3, in <module> import django.core.handlers.wsgi ImportError: No module named django.core.handlers.wsgi |
Then I figured out the reason, I didn’t put the requirements.txt in the right directory. So I move requirements.txt to the same directory where wsgi.py in.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
2011-07-22 XX:XX:XX [api] Waiting for the build. (It may take a few minutes) 2011-07-22 XX:XX:XX [www.0] The build started 2011-07-22 XX:XX:XX [www.0] Fetched code revision rsync-yyyyyyyyyy.y 2011-07-22 XX:XX:XX [www.0] Downloading/unpacking django (from -r requirements.txt (line 1)) 2011-07-22 XX:XX:XX [www.0] Creating supposed download cache at /home/dotcloud/.pip-cache 2011-07-22 XX:XX:XX [www.0] Storing download in cache at /home/dotcloud/.pip-cache/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2FD%2FDjango%2FDjango-1.3.tar.gz 2011-07-22 XX:XX:XX [www.0] Running setup.py egg_info for package django 2011-07-22 XX:XX:XX [www.0] Installing collected packages: django 2011-07-22 XX:XX:XX [www.0] Running setup.py install for django 2011-07-22 XX:XX:XX [www.0] changing mode of build/scripts-2.6/django-admin.py from 644 to 755 2011-07-22 XX:XX:XX [www.0] changing mode of /home/dotcloud/env/bin/django-admin.py to 755 2011-07-22 XX:XX:XX [www.0] Successfully installed django 2011-07-22 XX:XX:XX [www.0] Cleaning up... 2011-07-22 XX:XX:XX [www.0] Reloading nginx configuration: nginx. 2011-07-22 XX:XX:XX [www.0] uwsgi: stopped 2011-07-22 XX:XX:XX [www.0] uwsgi: started 2011-07-22 XX:XX:XX [www.0] The build finished successfully 2011-07-22 XX:XX:XX [api] Deploy finished |
But wait, I still got the error message:
1 2 3 4 5 6 7 8 |
added /home/dotcloud/current to pythonpath. interpreter for app 0 initialized. application 0 () ready setting default application to 0 Traceback (most recent call last): File "/home/dotcloud/current/wsgi.py", line 8, in application return djangoapplication(environ, start_response) NameError: global name 'djangoapplication' is not defined |
To investigate, let’s what happened to the wsgi.py
1 2 3 4 5 6 7 8 |
import os os.environ['DJANGO_SETTINGS_MODULE'] = '.' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() def application(environ, start_response): if 'SCRIPT_NAME' in environ: del environ['SCRIPT_NAME'] return djangoapplication(environ, start_response) |
So I should follow the guide, let’s commented out line 4~8. But I got another error:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
raceback (most recent call last): File "/home/dotcloud/env/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 250, in __call__ self.load_middleware() File "/home/dotcloud/env/lib/python2.6/site-packages/django/core/handlers/base.py", line 39, in load_middleware for middleware_path in settings.MIDDLEWARE_CLASSES: File "/home/dotcloud/env/lib/python2.6/site-packages/django/utils/functional.py", line 276, in __getattr__ self._setup() File "/home/dotcloud/env/lib/python2.6/site-packages/django/conf/__init__.py", line 42, in _setup self._wrapped = Settings(settings_module) File "/home/dotcloud/env/lib/python2.6/site-packages/django/conf/__init__.py", line 87, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) File "/home/dotcloud/env/lib/python2.6/site-packages/django/utils/importlib.py", line 28, in import_module raise TypeError("relative imports require the 'package' argument") TypeError: relative imports require the 'package' argument |
The similar problem reported on dotcloud forum can be found here. However, I found the official document is not suitable for me, at least I didn’t want to add any extra files to my original repository. So the final version of dotcloud.yml, wsgi.py is here:
dotcloud.yml:
1 2 3 |
www: type: python # approot: djangoproject # comment the approot, otherwise you need to put wsgi.py/requirements.txt in this directory |
wsgi.py: (Note the line 2, 3 is for django path search, line 4 is to specify which settings.py to be loaded)
1 2 3 4 5 6 |
import os import sys sys.path = sys.path + ["/home/dotcloud/current/djangoproject/"] os.environ['DJANGO_SETTINGS_MODULE'] = 'djangoproject.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() |
Finally, my django project rocks on DotCloud, and the best part is I don’t have to add any extra files to my project directory.