Kenny Ho
Kenny Ho

Reputation: 423

A way to save the generated HTML from Django Views?

I'm trying to save all the HTML pages from the model objects I'm querying.

For instance for every model_id I have in the database, I want to save the http://127.0.0.1:8080/model_id.

I'm currently connecting to the local server shown above, and pinging through every http://127.0.0.1:8080/#id1, http://127.0.0.1:8080/#id2, http://127.0.0.1:8080/#id600, etc.

Is there a way I can get the html without using the local server to query?

Upvotes: 1

Views: 272

Answers (1)

Alasdair
Alasdair

Reputation: 309089

You could use the Django test client. The response's content contains the html of the page.

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

Upvotes: 2

Related Questions