Posts Tagged ‘save url

Generate and save a static page in Django

leave a comment »

Generate and save a static page in Django.

html/static.html is a Django template
data is the data you want to pass into the page
static(request) is a function mapped to a url in

Visiting the page will generate this static file


from django.template.loader import render_to_string

def static(request):
    results = render_to_string('html/static.html', {'content': html})
    with open(r'C:tempstatic.html','w') as f:

Written by M Kapoor

August 23, 2018 at 4:56 am

Download and save file using Python Requests

leave a comment »

Download and save a file using the Python requests library.

url = URL to download
filename = Name of local file for url

import requests

url = ''

response = requests.get(url)
with open(filename, 'wb') as f:

Written by M Kapoor

February 2, 2017 at 4:46 pm

Posted in python

Tagged with ,