Using Django for mostly static sites
goodcode.io
goodcode.io
[1]http://mezzanine.jupo.org/ [2]http://mezzanine.jupo.org/docs/deployment.html [3]http://mezzanine.jupo.org/docs/caching-strategy.html
Django is still needed here if you want to have form processing (unless you use 3rd party service), and useful if you want to have templating (unless you want to use Jekyll, Hyde, or similar static-generator tools).
So, while Nginx/Apache would definitely speed up things, they're not enough. On the other hand, you can build a reasonably[0] fast "almost" static site with Django, and have it deployed on either your Linux server, or Heroku, or another PaaS.
[0] What's "reasonably fast"? my hunch tells me that the simple setup outlined here could take quite a beating (unless intentionally attacked with slowloris or similar attacks, or serving heavy static assets). It'll be fun to test it.
Especially with virtualenvs and such.
./manage.py collectstatic
and you have nginx serving the truly static files while still allowing Django to manage your non-static assets.This is how I run my site, and it works pretty darned well. Let nginx do the caching of static files, compression, and SSL management, letting Django just worry about its small domain of non-static files.
The one downside is that nginx will not necessairly detect when a static file has changed, requiring a bit of effort to ensure that new versions of a static file are puled, either through filename versioning, or `?1` on the end of your static URLs.
With aggressive caching of all static pages it is fast as hell, and I love the django ecosystem. Adding search was as easy as dropping in django-haystack and adding like 5 lines of code. django-mptt has been brilliant for easily querying and manipulating comment trees.
It's possible to do small sites with django but it requires you to learn a lot of stuff you don't necessarily need. Flask is a better choice for small/nearly-static sites if you're not already familiar with a web framework.
http://flask.pocoo.org/docs/quickstart/
I used it in conjunction with Bootstrap and Heroku to throw a personal site together in an evening, following this tutorial:
http://www.shea.io/lightweight-python-apps-with-flask-twitte...
What am I missing by not knowing Flask?
[0] - http://www.sinatrarb.com/ [1] - http://www.webfaction.com/?affiliate=mbesto
Simply put, a web interface is often more convenient so I can update things easier on the go, and it's good to have a place to host experiments too.
I have used various static site generators but none of them seemed to be significantly less work to get going than a small django app on heroku. Though I've been using Django for a few years, so there is simply no learning curve left.
This one if I remember correctly: https://github.com/timmyomahony/django-pagedown
One unintended (and great) side-effect of a Dropbox-hosted site is that you get mirrors for free (they all update together).
$ pip install djangothis
$ cat > views.py
from importd import d
@d
def hello(request):
return d.HttpResponse("hello there")
^D
$ djangothis
Validating models...
0 errors found
February 18, 2014 - 16:43:31
Django version 1.6.2, using settings None
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Any html files would be automatically served, files in static folder in current folder will automatically be mapped to /static/ and so on.Works like a charm.
Database-first thinking for content sites is just wrong. I've done it based on this same argument, and I've learned my lesson.
The problem isn't showing the data, it's storing it. I have different computers gathering the data and deploying my site, so I would have to set up an elaborate solution, and I would still not be able to do A/B tests, sending email for new content, auto-Tweeting, etc.
Nice way to keep the site static but add a bit of variability.
Also, the bigger problem was, indeed, data storage, not display.