Package: django-static-sites
django-static-sitesdjango-static-sitesis an easy to useDjangoapp that allow you to create a static sites with the power of Django
template system. You can render an existingDjangoview by adding a decorator or you can create an empty project
optimized fordjango-static-sitesuse. You can specify multiple configuration for multiple deploy type.GitHubHow to startinstalldjango-static-sitesin your python path or in yourvirtualenvpath
(pip install django-static-sites) or (pip install https://github.com/ciotto/django-static-sites/archive/master.zip)create an empty optimized project bydjango-static-admin startproject PROJECT_NAMEcommandmove to thePROJECT_NAMEfolder and create site bypython manage.py startsite SITE_NAMEcommandmigratepython manage.py migratedeploypython manage.py deploystart serverpython manage.py runserverenjoy it athttp://127.0.0.1:8000:-)How to useIf you want to use theDjangotemplate system, you must to add a function in yourviews.pyfile and add the@staticviewdecorator:@staticviewdefindex(request):ctx={'title':'Hello world!'}returnrender_to_response('index.html',ctx,context_instance=RequestContext(request))and theindex.htmltemplate file in your templates folder:<!DOCTYPE html><htmllang="it"><head><metacharset="UTF-8"><title>{{ title }}</title></head><body><h1>{{ title }}</h1></body></html>When you deploy (python manage.py deployorautodeploy),django-static-sitescreate theindex.htmlusingindex.htmltemplate.If you want to add an rendered javascript file, you can create a view:@staticview(path={'demo':'asd/test.js','':'js/test.js'})defjs__test(request):ctx={'title':'Hello world!'}returnrender_to_response('test.js',ctx,context_instance=RequestContext(request))and the relatinetest.jstemplate:vartext='{{ title }}';alert(text);Thetest.jsdestination path are specified in@staticviewdecorator and is different for different deploy type so
we must add'js_path': js__test.path.get(deploy_type=deploy_type)in theindex.htmlcontext.deploy_typeare passed to the view
functions if is declared. Now we can add the import line in theindex.htmlfile:<scripttype="text/javascript"src="{{ js_path }}"></script>You can see this and more samples instaticsites/tests/samplesfolder; you can launch the deploy server for this
samples bymanage.py runserver --settings staticsites.tests.samples.SAMPLE_NAME.settingscommand.Other samplesHello worldHello world (with static)AWS S3/CloudFrontAWS S3/CloudFront (multiple remote)FTPAdd to an existing projectIf you want to integratedjango-static-sitesin existing project you must to:addstaticsitesin your INSTALLED_APPS (replace django.contrib.staticfiles)If you want to use Django development server to serve the deployed static site:add this lines at yoururl.py# Serve default deploy folder as site rootifsettings.DEBUG:urlpatterns+=[url(r'^(?:%s)?$'%get_default_index(deploy_type='dev'),serve,{'document_root':get_deploy_root(deploy_type='dev'),'path':get_default_index(deploy_type='dev')}),url(r'^(?P<path>.*)$',serve,{'document_root':get_deploy_root(deploy_type='dev')}),]Remote deploydjango-static-sitesuse theDjangoStoragesystem during the deploy procedure; by default the file are deployed
locally usingFileSystemStorage, but you can use any otherStoragewith the correct settings. In theAWS S3/CloudFrontsamples
I use thedjango-storagesAWS storage for deploying on Amazon S3 bucket.ToDodjango-static-sitesis work-in-progres:add automatic url patternautodeploystatic file optimizationrevert deploy if failGZip deployed filesminify deployed filescustom header for deployed filessinge configuration constant as dictionarydeploy on multiple remoteadd param check and raise Exceptionupdate testsdedicatedsettingsmodule for sampleadd tutorialsdeploy admin console