How do I supply an appropriate application.wsgi to Gunicorn?

1,742 views
Skip to first unread message

Christos Jonathan Seth Hayward

unread,
Nov 24, 2014, 4:21:05 PM11/24/14
to django...@googlegroups.com

've run through the documentation and am hitting the same pages over and over again. At present I've found documentation to run off an existing myapp.wsgi file, but documentation for how to make an appropriate wsgi file is a little harder to find.

If I want to make, proxied by Apache, the equivalent of, on an older version of Gunicorn etc.:

python manage.py run_gunicorn 0.0.0.0:8888

what should I be doing to supply a WSGI file for:

gunicorn project.wsgi:application

Thanks,

--
Christos Jonathan Seth Hayward
Christos Jonathan Seth Hayward, an Orthodox Christian author.

If you read just one of my books, you'll want The Best of Jonathan's Corner (Kindle).

Carl Meyer

unread,
Nov 24, 2014, 4:25:15 PM11/24/14
to django...@googlegroups.com
Hi,

On 11/24/2014 02:19 PM, Christos Jonathan Seth Hayward wrote:
> From
> http://stackoverflow.com/questions/27113466/how-can-i-deploy-django-gunicorn-under-apache-proxy
> :
>
> 've run through the documentation and am hitting the same pages over and
> over again. At present I've found documentation to run off an existing
> myapp.wsgi file, but documentation for how to make an appropriate wsgi file
> is a little harder to find.
>
> If I want to make, proxied by Apache, the equivalent of, on an older
> version of Gunicorn etc.:
>
> python manage.py run_gunicorn 0.0.0.0:8888
>
> what should I be doing to supply a WSGI file for:
>
> gunicorn project.wsgi:application

That depends a bit on your version of Django. For any Django version
since 1.4, 'django-admin.py startproject' should generate a wsgi.py file
in your project. If your project doesn't have one, you can run
'startproject' to quickly see what one should look like and copy it into
your project.

Carl

signature.asc

Christos Jonathan Seth Hayward

unread,
Nov 24, 2014, 4:39:34 PM11/24/14
to django...@googlegroups.com
Ok; wonder if I should upgrade Django.

I just ran a startproject earlier today (I can re-create it; I was just trying to get it running and see the start page in my browser before going further).

cjsh@ps306627:~/cynthia$ find . -name \*.wsgi

cjsh@ps306627:~/cynthia$ python manage.py shell

Python 2.6.6 (r266:84292, Aug 12 2014, 07:57:07) 

[GCC 4.4.5] on linux2

Type "help", "copyright", "credits" or "license" for more information.

(InteractiveConsole)

>>> import django

>>> dir(django)

['VERSION', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'conf', 'contrib', 'core', 'db', 'dispatch', 'forms', 'get_version', 'http', 'middleware', 'shortcuts', 'template', 'templatetags', 'test', 'utils', 'views']

>>> django.VERSION

(1, 6, 5, 'final', 0)

>>> 

​Further suggestions?


Thanks,


Carl

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5473A21F.8050801%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

Carl Meyer

unread,
Nov 24, 2014, 4:45:52 PM11/24/14
to django...@googlegroups.com


On 11/24/2014 02:38 PM, Christos Jonathan Seth Hayward wrote:
> Ok; wonder if I should upgrade Django.
>
> I just ran a startproject earlier today (I can re-create it; I was just
> trying to get it running and see the start page in my browser before going
> further).
>
> cjsh@ps306627:~/cynthia$ find . -name \*.wsgi

Your Django version is fine. The problem is that you're expecting to
find a file with the `.wsgi` extension. The file Django generates is
called `myproject/wsgi.py`, thus its dotted Python import path (which is
what you pass to gunicorn) is `myproject.wsgi`.

Carl

signature.asc

Christos Jonathan Seth Hayward

unread,
Nov 24, 2014, 4:57:22 PM11/24/14
to django...@googlegroups.com
Thanks so much!

Could you confirm the invocation?

cjsh@ps306627:~/cynthia$ gunicorn cynthia.wsgi 0.0.0.0:7777

usage: gunicorn [OPTIONS] [APP_MODULE]

gunicorn: error: No application module specified.

cjsh@ps306627:~/cynthia$ gunicorn cynthia.wsgi:application 0.0.0.0:7777

usage: gunicorn [OPTIONS] [APP_MODULE]

gunicorn: error: No application module specified.

cjsh@ps306627:~/cynthia$ gunicorn cynthia.wsgi:cynthia 0.0.0.0:7777

usage: gunicorn [OPTIONS] [APP_MODULE]

gunicorn: error: No application module specified.



Carl

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.

Carl Meyer

unread,
Nov 24, 2014, 5:01:10 PM11/24/14
to django...@googlegroups.com
On 11/24/2014 02:56 PM, Christos Jonathan Seth Hayward wrote:
> Thanks so much!
>
> Could you confirm the invocation?
>
> cjsh@ps306627:~/cynthia$ gunicorn cynthia.wsgi 0.0.0.0:7777
>
> usage: gunicorn [OPTIONS] [APP_MODULE]
>
> gunicorn: error: No application module specified.

That's the right invocation, but you need your python path set up to
include the directory that has `manage.py` in it (when you actually run
a `manage.py` command, this happens automatically, but not when you run
gunicorn).

There are a variety of ways that can be done, the simplest is to run
your gunicorn command from the same directory that contains `manage.py`
and set the PYTHONPATH env var:

PYTHONPATH=`pwd` gunicorn cynthia.wsgi 0.0.0.0:7777

Carl

signature.asc

Carl Meyer

unread,
Nov 24, 2014, 5:05:38 PM11/24/14
to django...@googlegroups.com
Sorry, I was focused on the Python issues, didn't notice that you're
trying to pass a bind address without using the `-b` option. This is
what you want:

PYTHONPATH=`pwd` gunicorn -b 0.0.0.0:7777 cynthia.wsgi

Carl

signature.asc

Christos Jonathan Seth Hayward

unread,
Nov 24, 2014, 5:08:14 PM11/24/14
to django...@googlegroups.com
And with that, I'm off and running!

Thank you for your help.


Carl

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages