Re: Generating server-side off-line HTML of Django pages ...

2018-06-12 Thread Bernd Wechner


On Monday, 4 June 2018 16:00:09 UTC+10, Bernd Wechner wrote:
>
> Say I have a page on my Django website (because I do) that I would like to 
> take a snapshot of on an automated basis on the server itself with a 
> crontab say. I imagine writing a small python script that I could run, that 
> loads Django, a settings file, knows a URL and has a way of saying "give me 
> the rendered page for that URL please" and save it in a file. 
>
> On way of course is open port 80 or 443, send an HTTP request and get the 
> HTTP response. But there is probably a better way that leaves the web and 
> UWSGI servers right out of the equation and just runs Django template 
> rendering code or a view itself and nabs the result.
>
> As usual, I'm both confident this is possible and that I'll nut out a way 
> to do it, but am throwing it out there in case:
>
> a) there's a canonical way to do this already that can be recommended
> b) I can save myself some time reading and experimenting if anyone whose 
> done this already shares their experience
>
> I will raise the bar one on the original question while I'm here, and 
> raise the spectre of autorun on page load javascript that the page may 
> have. Makes it hairier by a step. But it's not unusual for javascript to do 
> some rendering on page load - I have a page or two like that ;-), In that 
> case neither of these strategies are likely to work and either one might if 
> coupled with what would basically need to be, a rendering engine like 
> mozilla's. Does Python offer that I wonder, a way to pump a response (with 
> embedded Javascript) into a rendering engine and then save (or request) the 
> rendered page?
>
> Kind regards,
>
> Bernd.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/81c34e1c-71af-4a43-9e3b-088b3b1383fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generating server-side off-line HTML of Django pages ...

2018-06-06 Thread Melvyn Sopacua
On woensdag 6 juni 2018 18:25:35 CEST 'Anthony Flury' via Django users wrote:
> Does the test client execute javascript as well ? I can't remember.

No. Not even the HTML.

For that you need selenium, which is a whole different beast. The test client 
is used for "unit tests for views". Selenium is in the realm of integration 
tests, or acceptance tests if you will. It validates the end result, not a 
unit of code.
-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2061765.he2AIJnB6B%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: Generating server-side off-line HTML of Django pages ...

2018-06-06 Thread 'Anthony Flury' via Django users

Does the test client execute javascript as well ? I can't remember.

On 05/06/18 00:14, Bernd Wechner wrote:
Thanks Melvyn, looks exactly like what I wanted! Will investigate. I 
had a feeling this could not be a novel or unique use case.


Regards,

Bernd.

On Monday, 4 June 2018 20:09:25 UTC+10, Melvyn Sopacua wrote:

On maandag 4 juni 2018 08:00:08 CEST Bernd Wechner wrote:

> Say I have a page on my Django website (because I do) that I
would like to

> take a snapshot of on an automated basis on the server itself with a

> crontab say. I imagine writing a small python script that I
could run, that

> loads Django, a settings file, knows a URL and has a way of
saying "give me

> the rendered page for that URL please" and save it in a file.

...

> a) there's a canonical way to do this already that can be
recommended

Yep. The test client

...
if your template uses request related information (like logged in
user). The cheaper method is something like this code

,
but this only renders the template and you'd have to provide a
context so view code is bypassed.

-- 


Melvyn Sopacua

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/850bfcaa-0518-48ef-a827-087100efda92%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.



--
--
Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury *

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/03b51b49-d1b8-b7f4-9ff4-5d8d8ff3b54a%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generating server-side off-line HTML of Django pages ...

2018-06-04 Thread Bernd Wechner
Thanks Melvyn, looks exactly like what I wanted! Will investigate. I had a 
feeling this could not be a novel or unique use case.

Regards,

Bernd.

On Monday, 4 June 2018 20:09:25 UTC+10, Melvyn Sopacua wrote:
>
> On maandag 4 juni 2018 08:00:08 CEST Bernd Wechner wrote:
>
> > Say I have a page on my Django website (because I do) that I would like 
> to
>
> > take a snapshot of on an automated basis on the server itself with a
>
> > crontab say. I imagine writing a small python script that I could run, 
> that
>
> > loads Django, a settings file, knows a URL and has a way of saying "give 
> me
>
> > the rendered page for that URL please" and save it in a file.
>
>  
>
> ...
>
>  
>
> > a) there's a canonical way to do this already that can be recommended
>
>  
>
> Yep. The test client 
> ...
>  
> if your template uses request related information (like logged in user). 
> The cheaper method is something like this code 
> ,
>  
> but this only renders the template and you'd have to provide a context so 
> view code is bypassed.
>
>  
>
> -- 
>
> Melvyn Sopacua
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/850bfcaa-0518-48ef-a827-087100efda92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generating server-side off-line HTML of Django pages ...

2018-06-04 Thread Melvyn Sopacua
On maandag 4 juni 2018 08:00:08 CEST Bernd Wechner wrote:
> Say I have a page on my Django website (because I do) that I would like to
> take a snapshot of on an automated basis on the server itself with a
> crontab say. I imagine writing a small python script that I could run, that
> loads Django, a settings file, knows a URL and has a way of saying "give me
> the rendered page for that URL please" and save it in a file.

...

> a) there's a canonical way to do this already that can be recommended

Yep. The test client [1]... if your template uses request related information 
(like logged in 
user). The cheaper method is something like this code[2], but this only renders 
the 
template and you'd have to provide a context so view code is bypassed.

-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/2.0/topics/testing/tools/#the-test-client
[2] https://github.com/melvyn-sopacua/django_xtc/blob/master/xtc/__init__.py#L49

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3641770.R8fxcq3Jsz%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Generating server-side off-line HTML of Django pages ...

2018-06-04 Thread Bernd Wechner
Say I have a page on my Django website (because I do) that I would like to 
take a snapshot of on an automated basis on the server itself with a 
crontab say. I imagine writing a small python script that I could run, that 
loads Django, a settings file, knows a URL and has a way of saying "give me 
the rendered page for that URL please" and save it in a file. 

On way of course is open port 80 or 443, send an HTTP request and get the 
HTTP response. But there is probably a better way that leaves the web and 
UWSGI servers right out of the equation and just runs Django template 
rendering code or a view itself and nabs the result.

As usual, I'm both confident this is possible and that I'll nut out a way 
to do it, but am throwing it out there in case:

a) there's a canonical way to do this already that can be recommended
b) I can save myself some time reading and experimenting if anyone whose 
done this already shares their experience

I will raise the bar one on the original question while I'm here, and raise 
the spectre of autorun on page load javascript that the page may have. 
Makes it hairier by a step. But it's not unusual for javascript to do some 
rendering on page load - I have a page or two like that ;-), In that case 
neither of these strategies are likely to work and either one might if 
coupled with what would basically need to be, a rendering engine like 
mozilla's. Does Python offer that I wonder, a way to pump a response (with 
embedded Javascript) into a rendering engine and then save (or request) the 
rendered page?

Kind regards,

Bernd.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6353b82e-7f0d-465f-9eba-68ed207940a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.