简体   繁体   中英

Export Django view to static HTML files using Django API (i.e. not wget or other scraper)

I have several Django views that I want to export as a static HTML site (to host on AWS S3). The site doesn't use any authentication or dynamic features, so serving in static format is ideal.

Using Django StaticGenerator ( original source ) or wget -m seems like a fine solution, but they require I run my web server (even if it happens to just be manage.py runserver ).

I would prefer to use the Django API to retrieve the view's HTML. For example:

  1. Initialize the request object with a non-logged-in user;
  2. Pass this to my view function/method;
  3. Do something with returned HTML

The easiest way is to use django test client

>>> from django.test import Client
>>> c = Client()
>>> response = c.get('/')
>>> response.content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM