Skip to content

Instantly share code, notes, and snippets.

"""
Two things are wrong with Django's default `SECRET_KEY` system:
1. It is not random but pseudo-random
2. It saves and displays the SECRET_KEY in `settings.py`
This snippet
1. uses `SystemRandom()` instead to generate a random key
2. saves a local `secret.txt`
@renfredxh
renfredxh / soupURL.py
Last active December 21, 2015 15:59 — forked from simonw/gist:104413
Turn a BeautifulSoup form in to url encoded fields and default values - useful for screen scraping forms and then resubmitting them
from urllib.parse import urlencode
def extract_form_fields(self, soup):
"Turn a BeautifulSoup form into url encoded fields and default values"
fields = ""
for input in soup.findAll('input'):
# ignore submit/image with no name attribute
if input['type'] in ('submit', 'image') and not input.has_attr('name'):
continue