Deploying django

44 views
Skip to first unread message

João Marques

unread,
May 3, 2015, 4:08:01 PM5/3/15
to django...@googlegroups.com
Hey there guys, I'm starting to lose my hope in deploying my django project to a vps. Here is what I've done so far (notice that i'm a newbie and this is the first time): I've created my virtualenv and installed pip, django, mysqldb package and nginx (i think). I followed this tutorial: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-local-django-app-to-a-vps

There were, although a few missing points on the tutorial like on the gunicorn set-up, the command that's listed on the tutorial is outdated and, even with the help of gunicorn's documentation, I couldn't figure it out.

Now what happens when I run the server in "debug = False" is an error 500. Without the "debug = False" I get this:'Empty static prefix not permitted'.

Can you recommend me a good tutorial for me to follow?

ps. I still need to use this http://37.59.114.190:8001/ with the port, but I believe that is because of the gunicorn that i didn't set up.
Thank you so much for your time,

João Marques

Fellipe Henrique

unread,
May 3, 2015, 5:24:07 PM5/3/15
to Django Users
Hey man!!

In my setup, I use this: Gunicorn + nginx + supervisor

Please, share your confs files.. without them we can't help a lot!

T.·.F.·.A.·.     S+F
Fellipe Henrique P. Soares

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
Twitter: @fh_bash

--
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/79f73903-55d1-4c4c-a1d1-4a477bfd41ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mike Dewhirst

unread,
May 3, 2015, 7:16:00 PM5/3/15
to django...@googlegroups.com
On 4/05/2015 6:08 AM, João Marques wrote:
> Now what happens when I run the server in "debug = False" is an error
> 500. Without the "debug = False" I get this:'Empty static prefix not
> permitted'.

Googling that error brings up a few results. It seems to indicate a
problem with STATIC_ROOT and STATIC_URL when DEBUG is true and/or
misconfiguration of Nginx when DEBUG is false.

https://docs.djangoproject.com/en/1.8/howto/static-files/#deployment

Running collectstatic drops all your static files into the STATIC_ROOT
directory on the server and that is where Nginx has to find them. The
way it works is that when a user requests a static file in a URL, Nginx
has to recognise the URL prefix to the static file named. The Nginx
config you need is to make the recognised URL prefix point to a real
location on the server (ie where collectstatic previously put the static
files)

hth

Mike

João Marques

unread,
May 4, 2015, 4:30:08 AM5/4/15
to django...@googlegroups.com
Thanks for the answer, what are this configuration files that you speak of? I really don't know much about this whole deployment thing. From what i remenber i configured apache configuration and something called available-sites...
Message has been deleted

João Marques

unread,
May 4, 2015, 4:43:15 AM5/4/15
to django...@googlegroups.com
Oh I get it. I have a few questions:

1. Wheres should I configure my nginx?

2. Is there a any problem with my project folder structure? Because I do have my templates outside the static folder...

├── costum
├── manage.py
├── psi
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── middlewares.py
│   ├── middlewares.pyc
│   ├── __pycache__
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── static
│   ├── bower_components
│   ├── circle-progress.js
│   ├── css
│   ├── dist
│   └── js
├── static-root
├── templates
│   ├── admin-panel
│   ├── base.html
│   ├── home.html
│   ├── renderSolution.html
│   └── runAlgorithm.html
└── teste1
    ├── admin.py
    ├── admin.pyc
    ├── algorithm.py
    ├── binariesExchange.py
    ├── binaries.py
    ├── fitness.py
    ├── __init__.py
    ├── __init__.pyc
    ├── migrations
    ├── models.py
    ├── models.pyc
    ├── __pycache__
    ├── tests.py
    └── views.py

Mike Dewhirst

unread,
May 4, 2015, 7:00:22 AM5/4/15
to django...@googlegroups.com
On 4/05/2015 6:43 PM, João Marques wrote:
> Oh I get it. I have a few questions:
>
> 1. Wheres should I configure my nginx?

/etc/nginx (probably)

This is part of my nginx config ...


location /static/ {
root /home/mike/envs/myproject/static;
access_log off;
log_not_found off;
}

location /robots.txt {
root /home/mike/envs/myproject/static/robots;
access_log off;
log_not_found off;
}

location /favicon.ico {
root /home/mike/envs/myproject/static/img;
access_log off;
log_not_found off;
}



>
> 2. Is there a any problem with my project folder structure? Because I do
> have my templates outside the static folder...

Templates are not static files. They are part of Django's page rendering
mechanism. Static files are css, images and javascript plus other media
or files which don't need to be served *by* Django. You call such things
in your software by either naming them directly in your templates (like
css, js and images) or having variables in your templates which name
such static files.

Check the documentation starting at
https://docs.djangoproject.com/en/1.8/topics/templates/

I haven't had time to look at your project folder beyond noticing some
"interesting" folder names and files.

You should work through the tutorial (if you haven't already) and
discover the typical folder layout. It is easier to get the hang of
things if you stick with the conventional layout until you find a strong
reason to do things differently.

Good luck

Mike

>
> ├── costum
> ├── manage.py
> ├── psi
> │ ├── __init__.py
> │ ├── __init__.pyc
> │ ├── middlewares.py
> │ ├── middlewares.pyc
> │ ├── __pycache__
> │ ├── settings.py
> │ ├── settings.pyc
> │ ├── urls.py
> │ ├── urls.pyc
> │ ├── wsgi.py
> │ └── wsgi.pyc
> ├── static
> │ ├── bower_components
> │ ├── circle-progress.js
> │ ├── css
> │ ├── dist
> │ └── js
> ├── static-root
> ├── templates
> │ ├── admin-panel
> │ ├── base.html
> │ ├── home.html
> │ ├── renderSolution.html
> │ └── runAlgorithm.html
> └── teste1
> ├── admin.py
> ├── admin.pyc
> ├── algorithm.py
> ├── binariesExchange.py
> ├── binaries.py
> ├── fitness.py
> ├── __init__.py
> ├── __init__.pyc
> ├── migrations
> ├── models.py
> ├── models.pyc
> ├── __pycache__
> ├── tests.py
> └── views.py
>
>
> On Monday, 4 May 2015 00:16:00 UTC+1, Mike Dewhirst wrote:
>
> On 4/05/2015 6:08 AM, João Marques wrote:
> > Now what happens when I run the server in "debug = False" is an
> error
> > 500. Without the "debug = False" I get this:'Empty static prefix not
> > permitted'.
>
> Googling that error brings up a few results. It seems to indicate a
> problem with STATIC_ROOT and STATIC_URL when DEBUG is true and/or
> misconfiguration of Nginx when DEBUG is false.
>
> https://docs.djangoproject.com/en/1.8/howto/static-files/#deployment
> <https://docs.djangoproject.com/en/1.8/howto/static-files/#deployment>
>
> Running collectstatic drops all your static files into the STATIC_ROOT
> directory on the server and that is where Nginx has to find them. The
> way it works is that when a user requests a static file in a URL, Nginx
> has to recognise the URL prefix to the static file named. The Nginx
> config you need is to make the recognised URL prefix point to a real
> location on the server (ie where collectstatic previously put the
> static
> files)
>
> hth
>
> Mike
>
> --
> 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
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto: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/a7a5ded5-d804-4bcd-9327-ec1bd385707b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a7a5ded5-d804-4bcd-9327-ec1bd385707b%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages