Login

Snippets by pakal

Snippet List

Geoip middleware to restrict users to a set of allowed countries

This middleware uses Django's Geoip support (https://docs.djangoproject.com/fr/2.2/ref/contrib/gis/geoip2/), as well as axes's package helper to retrieve IP address (since Django's REMOTE_ADDR might be wrong when behind a reverse proxy). Ensure your geolite DB files are up to date (eg. with https://djangosnippets.org/snippets/10674/). The checker is optional, but ensures that security is not broken due to a misspelled/missing GEOIP_COUNTRY_WHITELIST.

  • middleware
  • ip
  • country
  • geoip
  • restriction
  • blocker
Read More

CBV to mix FormView and DetailView functionalities

Use this to display an object on a page AND be able to process a form on this page. This is just a copy of the [Django docs advice](https://docs.djangoproject.com/en/2.2/topics/class-based-views/mixins/#using-formmixin-with-detailview), but put as a reusable, standalone View.

  • view
  • form
  • cbv
  • detail
Read More

pakal has posted 4 snippets.