The canonical notion of urls ending in slashes dates from a web where urls were used to access documents and files this is no longer the case so keeping your urls witouth trailing slashes makes them prettier. The problem is that many people/blogs/spiders/browsers could end up with a url with slashes which can be problematic for you SEO, or confuse users.
This script is for sites with no trailing slash dicipline in their urls, and to prevent everybody getting a horrible 404 for a simple slash you just got to remove it and issue a permanent redirect (301) and you'll get your pretty urls your cake and eat it too.
I must stress, you will have to edit all your public urls removing the slashes like so:
url(r'^login$', login,}
If you forget, to edit them and visit the url, your browser will remember the redirect and you'll have to clean the browsing history to fix it.
- permanent redirect
- no slashes
- no slash
Template filter that divides a list into an exact number of columns.
The number of columns is guaranteed.
Example (list == [1,2,3,4,5,6,7,8,9,10]):
{% for column in list|columns:3 %}
<ul>
{% for item in column %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endfor %}
Result:
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<ul>
<li>5</li>
<li>6</li>
<li>7</li>
</ul>
<ul>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
By Davide Muzzarelli
- filter
- template-filter
- list
- columns
TemplateZipFile is a class for creating ZipFiles out of Django templates.
Usage example:
from zipfile import ZIP_DEFLATED
from django_zipfile import TemplateZipFile
def myview(request, object_id):
obj = get_object_or_404(MyModel, pk=object_id)
context = {
'object': obj
}
response = HttpResponse(mimetype='application/octet-stream')
response['Content-Disposition'] = 'attachment; filename=myfile.zip'
container = TemplateZipFile(response, mode='w', compression=ZIP_DEFLATED, template_root='myapp/myzipskeleton/')
container.add_template('mimetype')
container.add_template('META-INF/container.xml')
container.add_template('chapter1.html', context=context)
container.close()
return response