Thank you very very much! It's no longer black magic. I did not think about the fact that the template just becomes a simple HTML page and the client browser has to get the javascript as requested.

Johnf

On 04/23/2015 07:35 AM, C. Kirby wrote:
Hi John,
It can be a little confusing. Once you are in production and not using runserver, django does not serve the static files. This is what happens:

The template expands this snippet with a tag:
<link href = "{% static 'css/bootstrap.min.css' %}" rel="stylesheet">

into (something like) this (Taking into account the STATIC_URL that Lachlan discussed above):
<link href = "/mystaticfolder/css/bootstrap.min.css" rel="stylesheet">
i.e. a regular link.

When the browser sees that it requests the page <host>/mystaticfolder/css/bootstrap.min.css from the webserver, which in your case is nginx. The location directive in your nginx configuration sets up where on the filesystem that url resolves to, and it serves the content back to the client.

The reason this is great it because, since no python is needed to serve the js, you don't have the overhead of python and django to serve static content (and webservers are highly tund to serve static content _fast_). For high load sites this can result in noticeable resource savings.

Hope that helps,
Kirby



On Wednesday, April 22, 2015 at 7:10:50 PM UTC-5, John Fabiani wrote:

    Thanks guys - that worked!!!!!!!!!

    I'm going to call it black magic - because to be truthful I don't
    understand how it really works.  If anyone has a better link than
    Django's on static files that explains what is really happening - it
    would be very helpful.

    Johnf

    On 04/22/2015 04:57 PM, Mike Dewhirst wrote:
    > On 23/04/2015 9:35 AM, john wrote:
    >> Hi,
    >> I have created a website that works well under "runserver".
     But when I
    >> use nginx and uwsgi the basic website comes up but it is
    missing the
    >> static file information. I have run "manage.py collectstatic"
    but still
    >> no static files are used.
    >>
    >> Reading the Django doc's tells me that I need the webserver to
    serve the
    >> static files.  Ok I think I can do that (maybe).  But I don't
    understand
    >> completely.  In my templates I have links like:
    >> <link href = "{% static 'css/bootstrap.min.css' %}"
    rel="stylesheet">
    >>
    >> How does the nginx server understand to provide the css file
    for my html
    >> page from the code above?
    >>
    >> I read that I can add a 'location' in the nginx config file but
    don't
    >> understand how nginx would understand to provide it when my
    template is
    >> called.
    >
    > You probably want three locations ... here are mine:
    >
    >     location /static/ {
    >         root            /home/mike/envs/pq5/project;
    >         access_log      off;
    >         log_not_found   off;
    >     }
    >
    >     location /robots.txt {
    >         root            /home/mike/envs/pq5/project/static;
    >         access_log      off;
    >         log_not_found   off;
    >     }
    >
    >     location /favicon.ico {
    >         root            /home/mike/envs/pq5/project/static/img;
    >         access_log      off;
    >         log_not_found   off;
    >
    > So whenever a client browser requests something prefixed by
    /static/
    > nginx sees that and substitutes the value of "root". Therefore,
    > collectstatic has to put your css files exactly where your template
    > says to look for them.
    >
    > Collectstatic knows exactly where by checking the value in
    > settings.STATIC_ROOT
    >
    > hth
    >
    > mike
    >
    >>
    >> Thanks for the help in advance.
    >>
    >> Johnf
    >>
    >>
    >

--
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+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto:django-users@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/18acfbb3-9f1f-4512-b881-c6764fdf5af2%40googlegroups.com <https://groups.google.com/d/msgid/django-users/18acfbb3-9f1f-4512-b881-c6764fdf5af2%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/553905C1.9090300%40jfcomputer.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to