How do I make my droplet run Django from my virtualenv?

January 31, 2015 9.9k views

I did the 1-click Ubuntu/Django install. I’m trying however to run my Django project I migrated over which is contained within a virtualenv. Is there a config file with wsgi or nginx I need to edit to “point” it at virtualenv? I currently have my project migrated over but when I visit the IP for the droplet, all I see is the generic “congratulations on your first django page” message. What am I doing wrong?

9 comments
  • Where does the 1-click install put the uwsgi.ini file?

  • Did you ever figure this out. I’m having the same issues.

  • first pip install guinicorn into your virtualenv

    Then you need to edit /etc/init/guincorn.conf to point to your project and the gunicorn in your virtualenv.

    It is also important to note that if you have any environment variables in your django project they need to be included in the .conf as well

    mine:

    description "Start Gunicorn Daemon for Forte Project"
    
    author "Jeffrey Balinsky jeff@fortelinea.com"
    
    start on (filesystem)
    stop on runlevel [016]
    
    
    env TEMPLATE_DIR=/home/django/forte/templates
    env STATIC_DIR=/home/django/forte/static
    env DBUSR=django
    env DBPW=*******
    
    respawn
    
    chdir /home/django/forte
    
    exec /home/django/prod/bin/gunicorn \
        --bind=0.0.0.0:9000 \
        forte.wsgi
    
  • Thanks for that.

    I’m guessing /home/django/forte is your project folder and /home/django/prod your virtualenv?

    I just get the following when restarting gunicorn

    stop: Unknown instance:
    start: Job failed to start

  • you guessed right

    i forgot to mention when you change the .conf file you have to run:

    initctl reload-configuration

    then

    restart gunicorn

  • Show 4 more comments
2 Answers

Sorry to see that your question hasn’t received an answer yet. Unfortunately, after this much time, it is unlikely that an answer for this specific question will be provided. For people still landing here via search, check out this updated tutorial set up Django using a virtualenv:

by Jeremy Morris
In this tutorial, we will set up a Django development environment. We’ll install Python 3, pip 3, Django and virtualenv in order to provide you with the tools necessary for developing web applications with Django.
Have another answer? Share your knowledge.