Re: Where to load global static data?

79 views
Skip to first unread message

Mike Dewhirst

unread,
Apr 5, 2012, 3:43:45 AM4/5/12
to django...@googlegroups.com
On 5/04/2012 4:53pm, Lars Ruoff wrote:
> Sorry, that message went off (twice!) while i was in the middle of
> typing :-)
>
> The question is:
> How do i load static global data once and for all at server startup.

I think you would need to implement caching. See
https://docs.djangoproject.com/en/dev/topics/cache/

Also, if you really want it pre-loaded you would probably need to write
a program to ensure all static data is fetched at webserver restart.

But, normally static data isn't served by Django. It is usually kept in
a separate location from your Django code and served directly by the
webserver without getting Django involved at all. See
https://docs.djangoproject.com/en/dev/howto/static-files/

Good luck

Mike

> I.e. i'd like to have that data in memory and accessible from any view
> during the lifetime of the server, so that it needs NOT to be loaded
> for any access to the site/view.
>
> Hope the question is clear.
> Regards,
> Lars
>

Lars Ruoff

unread,
Apr 5, 2012, 8:21:28 AM4/5/12
to Django users
On Apr 5, 9:43 am, Mike Dewhirst <mi...@dewhirst.com.au> wrote:
> On 5/04/2012 4:53pm, Lars Ruoff wrote:
>
> > Sorry, that message went off (twice!) while i was in the middle of
> > typing :-)
>
> > The question is:
> > How do i load static global data once and for all at server startup.
>
> I think you would need to implement caching. Seehttps://docs.djangoproject.com/en/dev/topics/cache/
>
> Also, if you really want it pre-loaded you would probably need to write
> a program to ensure all static data is fetched at webserver restart.
>
> But, normally static data isn't served by Django. It is usually kept in
> a separate location from your Django code and served directly by the
> webserver without getting Django involved at all. Seehttps://docs.djangoproject.com/en/dev/howto/static-files/
>
> Good luck
>
> Mike


thanks Mike.
sorry i had some problem with this thread so i tried to delete it and
started another one.
=> Please continue here:
http://groups.google.com/group/django-users/browse_thread/thread/9659ff188c59dc9b/3cae53e95b368229

In short, i'm not talking about static data like pages/ressources to
be served by the server, but static in the sense constant python data
that is going to be read in once and then acessed at different parts
of the python code.

Joel Goldstick

unread,
Apr 5, 2012, 2:57:55 PM4/5/12
to django...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>

Why do you want it to be global? You can create an app or just put
your data in one of your apps and import it to the other apps that
read it.
in my_dataset.py write code which (obviously more work than this):

my_stuff = (1,2,3)

from mybigdatasetapp.my_dataset import my_stuff

--
Joel Goldstick

Reply all
Reply to author
Forward
0 new messages