A trick to force autoreloading, in case of changes in views.py

13 views
Skip to first unread message

n00m

unread,
Sep 12, 2008, 9:30:40 AM9/12/08
to Django users

1.
Rename views.py to (say) views_base.py

2.
Create a new views.py file, with code like this:


import os.path
import views_base

def test(request):
if os.path.isfile(__file__ + '1'):
reload(views_base)
return views_base.test(request)

def tables(request, table_name=None, cur_page=1):
if os.path.isfile(__file__ + '1'):
reload(views_base)
return views_base.tables(request, table_name, cur_page)

..............
..............
..............


Idea is straightforward:

functions test, tables etc are from views_base.py (former views.py);
if exists dummy file views.py1, which existence is a sign of changes
made in views_base.py, then reload the whole thing

Just put this dummy empty file views.py1 into the dir of views.py
(if at the time you need no AutoReload just delete or rename it).

Now you can edit your views_base.py and see the changes in action,
without restarting Web Server (except of args of defs(request, args).

Thomas Guettler

unread,
Sep 12, 2008, 9:36:04 AM9/12/08
to django...@googlegroups.com
Hi,

I use apache mod_wsgi (WSGIDaemonProcess) and for development
maximum-requests=1.

This way I don't need to change any code for reloading: Just hit ctrl-r
(reload in firefox).

Thomas

n00m schrieb:


--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

n00m

unread,
Sep 12, 2008, 10:38:56 AM9/12/08
to Django users

Hi, Tom!

Now imagine production environment on an hoster machine
on which Apache is running in 24/7 mode.
===========================================
Of course, I didn't mean my trick for home/localhost

Cheers!

n00m

unread,
Sep 12, 2008, 10:47:19 AM9/12/08
to Django users
> This way I don't need to change any code

Seems you absolutely misunderstand what I was talking about but
you dared, in bold manner, to label my subject as a spam.

Keith Eberle

unread,
Sep 12, 2008, 11:11:00 AM9/12/08
to django...@googlegroups.com
i don't think he marked it as spam, but rather "spam assassin" did...

keith

n00m

unread,
Sep 12, 2008, 11:58:04 AM9/12/08
to Django users

Much better just to keep in views.py a "secret",
not for public, "reloader" page:

===================================================
views.py
===================================================

import views_base

def reloader(request):
reload(views_base)
return views_base.HttpResponse('views_base.py reloaded!')

...........
...........

def test(request):
return views_base.test(request)

def index(request):
return views_base.index(request)

def tables(request, table_name=None, cur_page=1):
return views_base.tables(request, table_name, cur_page)

===================================================

After each visiting the reloader page
the whole site get silently refreshed.

All the rest defs here are just thin wrappers around
"true" defs from "true views.py" == views_base.py.

n00m

unread,
Sep 12, 2008, 12:00:29 PM9/12/08
to Django users

On Sep 12, 6:11 pm, "Keith Eberle" <keith.ebe...@gmail.com> wrote:
> i don't think he marked it as spam, but rather "spam assassin" did...
>
> keith

If so then my sincere apologies to Thomas Guettler

David Thole

unread,
Sep 12, 2008, 1:04:26 PM9/12/08
to Django users
Just curious, are you using the django built in web server for
development? The reason why I'm asking is because I don't recall
having any problems at all when changing a view and it not picking up
the change. Every time I save a file, the build in web server
automatically updates it.

If you're using apache - do you mind if I ask what advantages you have
with Apache that the built in web server doesn't have? Not
questioning, just very curious is all.

-David
http://www.thedarktrumpet.com

James Matthews

unread,
Sep 12, 2008, 4:45:29 PM9/12/08
to django...@googlegroups.com
He might be using --no-reload

Graham Dumpleton

unread,
Sep 12, 2008, 6:42:54 PM9/12/08
to Django users


On Sep 12, 11:36 pm, Thomas Guettler <h...@tbz-pariv.de> wrote:
> Hi,
>
> I use apachemod_wsgi(WSGIDaemonProcess) and for development
> maximum-requests=1.
>
> This way I don't need to change any code for reloading: Just hit ctrl-r
> (reload in firefox).

I would recommend against maximum-requests=1 for mod_wsgi daemon mode.
This will give worse performance than Python development server.

Read:

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

In there you will see that for mod_wsgi daemon mode, to cause a
restart you just need to touch the WSGI script after having made a set
of changes.

If you are too lazy to touch the WSGI script file, then see the in
process restart monitor in section 'Restarting Daemon Processes'. With
this, at least it only restarts when code changes and not on every
request regardless of whether a change is made or not.

Graham
> Thomas Guettler,http://www.thomas-guettler.de/

n00m

unread,
Sep 12, 2008, 7:06:32 PM9/12/08
to Django users

On Sep 12, 8:04 pm, David Thole <dth...@gmail.com> wrote:
> Just curious,  are you using the django built in web server for
> development?  The reason why I'm asking is because I don't recall
> having any problems at all when changing a view and it not picking up
> the change.  Every time I save a file, the build in web server
> automatically updates it.
>
> If you're using apache - do you mind if I ask what advantages you have
> with Apache that the built in web server doesn't have?  Not
> questioning, just very curious is all.
>
> -Davidhttp://www.thedarktrumpet.com

Of course, I know the built-in web server (and its
autoreloading mechanics) but I use Apache (+ mod_python)
instead, mostly for to keep my eye on how css works etc.
Moreover, for me it's not a hard deed to click on "Restart"
in Apache's icon in systray.
But how can I do that on an hoster's machine if I want to
see changes in my views_.py right here, right now?

PS I'm quite aware of option MaxRequestsPerChild, but
again it's not for hosting environment, it's for "home" use.

n00m

unread,
Sep 14, 2008, 1:59:44 PM9/14/08
to Django users
What is the http://www.thomas-guettler.de/?

Remove from your sig this link to your f**king spam-like site.

On Sep 12, 4:36 pm, Thomas Guettler <h...@tbz-pariv.de> wrote:
> Thomas Guettler,http://www.thomas-guettler.de/

Steve Holden

unread,
Sep 14, 2008, 2:18:11 PM9/14/08
to django...@googlegroups.com
If you think it's spam, why add another link to Google by quoting the
URL (twice) in your message?


regards
Steve

Steve Holden

unread,
Sep 14, 2008, 2:28:03 PM9/14/08
to django...@googlegroups.com
Steve Holden wrote:
> n00m wrote:
>> What is the http:[...]?

>>
>> Remove from your sig this link to your f**king spam-like site.
>>
>> On Sep 12, 4:36 pm, Thomas Guettler <h...@tbz-pariv.de> wrote:
>>
>>> Thomas Guettler[...]

> If you think it's spam, why add another link to Google by quoting the
> URL (twice) in your message?
>
Aah, don't you just love the days you make the same mistake you
criticize other people for?
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Martin Diers

unread,
Sep 14, 2008, 6:47:25 PM9/14/08
to django...@googlegroups.com

Chill out. It's a personal website - no product being sold or
advertised.

If this group were moderated, you would no doubt be bounced for that
comment. If you treat others here with such disdain, do not expect to
be treated any better.

n00m

unread,
Sep 14, 2008, 9:19:48 PM9/14/08
to Django users

Next time you open your own thread
let me know:
I'll mark it as ***SPAM***
and we'll see how tolerant *you* are.

lingrlongr

unread,
Sep 14, 2008, 11:24:08 PM9/14/08
to Django users
Are we still on this!?!? There are SPAM filters (like Spam Assassin)
that automatically add this in the subject if it this an email is
SPAM. Relax!

Thomas Guettler

unread,
Sep 15, 2008, 3:58:57 AM9/15/08
to django...@googlegroups.com
n00m schrieb:

>> This way I don't need to change any code
>>
>
> Seems you absolutely misunderstand what I was talking about but
> you dared, in bold manner, to label my subject as a spam.
>
I am sorry. Some mail filter which is not under my control added the string
to the subject. I just hit reply without removing it.

Thomas

n00m

unread,
Sep 15, 2008, 8:20:59 AM9/15/08
to Django users

It's OK, Tom. Let's forget about this.

Cheers!
Reply all
Reply to author
Forward
0 new messages