django-static-sites
django-static-sites is an easy to use Django app that allow you to create a static sites with the power of Django template system. You can render an existing Django view by adding a decorator or you can create an empty project optimized for django-static-sites use. You can specify multiple configuration for multiple deploy type.
How to start
- install django-static-sites in your python path or in your virtualenv path
(
pip install django-static-sites) or (pip install https://github.com/ciotto/django-static-sites/archive/master.zip) - create an empty optimized project by
django-static-admin startproject PROJECT_NAMEcommand - move to the
PROJECT_NAMEfolder and create site bypython manage.py startsite SITE_NAMEcommand - migrate
python manage.py migrate - deploy
python manage.py deploy - start server
python manage.py runserver - enjoy it at http://127.0.0.1:8000 :-)
How to use
If you want to use the Django template system, you must to add a function in your views.py file and add the
@staticview decorator:
@staticview
def index(request):
ctx = {'title': 'Hello world!'}
return render_to_response('index.html', ctx, context_instance=RequestContext(request))
and the index.html template file in your templates folder:
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>{{ title }}</title>
</head>
<body>
<h1>{{ title }}</h1>
</body>
</html>
When you deploy (python manage.py deploy or autodeploy), django-static-sites create the index.html using
index.html template.
If you want to add an rendered javascript file, you can create a view:
@staticview(path={'demo': 'asd/test.js', '': 'js/test.js'})
def js__test(request):
ctx = {'title': 'Hello world!'}
return render_to_response('test.js', ctx, context_instance=RequestContext(request))
and the relatine test.js template:
var text = '{{ title }}';
alert(text);
The test.js destination path are specified in @staticview decorator and is different for different deploy type so
we must add 'js_path': js__test.path.get(deploy_type=deploy_type) in the index.html context. deploy_type are passed to the view
functions if is declared. Now we can add the import line in the index.html file:
<script type="text/javascript" src="{{ js_path }}"></script>
You can see this and more samples in staticsites/tests/samples folder; you can launch the deploy server for this
samples by manage.py runserver --settings staticsites.tests.samples.SAMPLE_NAME.settings command.
Other samples
Add to an existing project
If you want to integrate django-static-sites in existing project you must to:
- add
staticsitesin 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 your
url.py
# Serve default deploy folder as site root
if settings.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 deploy
django-static-sites use the Django Storage system during the deploy procedure; by default the file are deployed
locally using FileSystemStorage, but you can use any other Storage with the correct settings. In the
AWS S3/CloudFront samples
I use the django-storages AWS storage for deploying on Amazon S3 bucket.
ToDo
django-static-sites is work-in-progres:
- add automatic url pattern
autodeploystatic file optimization- revert deploy if fail
GZip deployed filesminify deployed filescustom header for deployed filessinge configuration constant as dictionarydeploy on multiple remote- add param check and raise Exception
- update tests
dedicated settings module for sampleadd tutorialsdeploy admin console
Metadata
Release files for django-static-sites 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-static-sites-0.0.8.tar.gz | 31.7 kB | Without provenance | Details for django-static-sites-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_static_sites-0.0.8-py2-none-any.whl | Python 2 | none | any | Details for django_static_sites-0.0.8-py2-none-any.whl |
Total release size: 82.2 kB
Release files / django-static-sites-0.0.8.tar.gz
| Download URL | django-static-sites-0.0.8.tar.gz |
|---|---|
| Size | 31.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
00bb187ede68bcb8fe35f16d9422788fe1e23daf662ba7d5d79097de5f716ed4
|
|
BLAKE2b-256 checksum How to use checksums |
e90cbd86c9679a285e7d8ce2da1fc240f18a2bef4f603215759e9059af82343d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/42.0.2 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.6
|
Release files / django_static_sites-0.0.8-py2-none-any.whl
| Download URL | django_static_sites-0.0.8-py2-none-any.whl |
|---|---|
| Size | 50.5 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
1862a97f2fc1a66975b6cef56d22020f9ae5a07e6df2b59b89bff0030240b3d8
|
|
BLAKE2b-256 checksum How to use checksums |
a79988394bdaba3a2a053e98e4716c6138c7173b4162dcb8c2182b9768de16af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/42.0.2 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.6
|
Security for django-static-sites 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.