Django in Production and Virtualenv

43 views
Skip to first unread message

Bruce Whealton

unread,
Jun 6, 2017, 10:08:11 PM6/6/17
to Django users
Hello all,
              There is a topic of confusion for me related to Apache and mod_wsgi.
I have been using two cloud providers DigitalOcean and PythonAnywhere.  The latter actually let me get
a home page being served by apache and not the development server ( which actually isn't even an option
on PythonAnywhere).  I could setup Django with one click and set it up with python3.4.  
          So, my questions are as follows: 1)  Virtualenv is described as so important but it seems it only can work in
development.  I mean once the terminal session closes, the venv that I setup is no longer active?
2) How do I get an IDE like Pycharm to recognize the Virtualenv?  I know I can select the compiler to be inside the 
Virtualenv but other libraries that I installed into that virtualenv, if the virtualenv is not active, then it won't find the 
installations of the different libraries.
3) I am thinking of using Docker to solve these problems but for some reason, I'd like to see how this was done without Docker.

4) I believe that nginx can work better as a reverse proxy whether using Docker or not, e.g. if I want to install WordPress 
on the same server or the same vps as Django/Flask, with nginx listening on port 80 the default.  I'm studying nginx now,
so, if apache can work as a reverse proxy, load balancer and web server, is it easier or better to use nginx for this?

Thanks so much for any help in advance,
Bruce   

Antonis Christofides

unread,
Jun 7, 2017, 2:04:21 AM6/7/17
to django...@googlegroups.com

Hi,

  1. Virtualenv can be used on production. You don't need to "activate" it, you can just execute the Python interpreter inside the virtualenv. "Virtualenv demystified" explains it in detail. With mod_wsgi you can use a virtualenv using WSGIPythonHome.
  2. I don't know PyCharm but it should be similar.
  3. You don't need Docker for that.
  4. Your question is not clear to me, but it is certain that both Apache and nginx can do what you want. You should not choose between them based on whether they can reverse proxy (they both can) or whether you can run several Django apps plus Wordpress on the same machine (you can with both, though Wordpress on Apache is easier). Note, however, that very often when people say "Apache" in the context of Django they frequently mean "Apache + mod_wsgi", whereas you can perfectly run Apache with Gunicorn. Also take a look at "Which components should I use in production?", which deals with many of your questions.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0e9b0985-ae29-49cd-8005-1be393db79f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Melvyn Sopacua

unread,
Jun 7, 2017, 3:28:34 AM6/7/17
to django...@googlegroups.com

On Tuesday 06 June 2017 19:08:10 Bruce Whealton wrote:

 

 

> 2) How do I get an IDE like Pycharm to recognize the Virtualenv? I

> know I can select the compiler

 

Interpreter.

 

> to be inside the

> Virtualenv but other libraries that I installed into that virtualenv,

> if the virtualenv is not active, then it won't find the

> installations of the different libraries.

 

Did you try it?

 

First off, PyCharm can make the virtualenv for you. Second, if you point it to the python interpreter inside the virtualenv, it will pick up the installed libraries.

File > Settings > Project > Project Interpreter.

 

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages