Login

All snippets written in Python

Snippet List

LocaleMiddleware without browser language discovery

This snippet holds your Django project from automatically changing language of the page to the best fitting one by discovering the client browser language. I personally needed to show the page to the user for the first time in the default language (English), although there were some translations. User can still change the language (via session cookies). Insert this middleware BEFORE the Django's `django.middleware.locale.LocaleMiddleware` in settings.

  • middleware
  • i18n
  • locale
Read More

Seeded Randomized Querysets w/ Pagination Mixin

Mixin to support pagination when randomizing querysets. Requirements: Postgres, Django Sessions Note: This shouldn't be used on large complex datasets. It utilizes the relatively slow method of '?' randomized sorting. Use with caution. Todo: MySQL support, Support for larger datasets

  • django
  • session
  • pagination
  • random
  • postgres
  • mixin
  • postgresql
  • cbv
  • seeded
Read More

Load dynamically loaded form javascript assets using dajax

I am used to load forms directly into modals using dajax but I found out I had to load the scripts using an ajax call from the browser. You can see here an example of a dynamically loaded form and the function used to load the scripts.

  • ajax
  • javascript
  • forms
  • script
  • dynamically-loaded-form
  • form-assets
  • dajax
Read More

Decorator @not_login_required

This is a simple django snippet! It is the *opposite of @login_required* decorator for Django views Example **@not_login_required** ``` def login_page(request): ... ```

  • decorator
Read More

get_querystring template tag

A Django Template tag used to construct urls with current querystring parameters. This is based on some code that I've written some years ago. Enjoy.

  • template
  • templatetag
  • querystring
Read More

django-constance generic view

For several projects I am using generic views instead of django-admin, I needed a generic view for constance instead of using their django-admin based app.

  • django-constance
Read More

django form template with bootstrap

## required * `{% load trans%}`before using this snippets * Add this [template filter](https://djangosnippets.org/snippets/2253/) to your custom templatetags and load it before using this snippets * Bootstrap framework

  • template
  • form
Read More

Decorate class-based views with regular decorators

Decorating a whole view involves overriding the dispatch method so you can decorate it, even if all you do is a passthrough. This creates a class decorator for decorating CBVs. For example, if you want to make a view require a login: @decorate_dispatch(login_required) class MyCBV(TemplateView): ...

Read More

2955 snippets posted so far.