How to execute some user defined codes (functions) when Django boot?
Dear all, Recently, I have developed a plugin system for my app, and I want to register those plugins when my app boot up, this need to execute some user defined codes (functions) in app boot procedure, I don't know where insert my registering codes to, anyone can help? Thank you. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Another question: how to apply custom variable into django template automatically?
Dear all, I have developed a CMS, which containing a dynamic menu. Because menu should be displayed on every page of my site, I need to write the menu variable into every view function against every page template, this is very boring... So is there some method to implement applying custom variable into django template automatically? I find some materials, may be RequestContext can handle it, but I don't know how to insert my custom variable into it? Anyone can help? Thank you! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to execute some user defined codes (functions) when Django boot?
Mathieu, What you said prompt me some idea: If I write my plugin registering codes into a middleware, and load it in django's settings.py, will it executed when app boot up? On 8月17日, 下午11时51分, Mathieu Leduc-Hamel wrote: > Paul, no it's not exactly the point. When you said some code on the boot up > it means really a piece of code shared by everyone and executed just one > time, by example, for mod_wsgi it would be when apache is starting. > > That's exactly what's done in the Pylons world to be able to load some piece > of code like the different middleware initialization. It could be useful > when you need launch some external long running process or anything like > that. > > But putting the code anywhere cause it would be evaluated when the code is > loaded is not safe cause you don't if everything was correctly loaded a this > time... > > > > On Tue, Aug 17, 2010 at 5:13 PM, Paul Winkler wrote: > > Seems to me that "on boot up" doesn't mean anything in a shared- > > nothing architecture like Django's. For example if you deploy on eg. > > mod_wsgi. > > You have no idea how long any particular thread or process is going to > > live, > > and no idea how often this "boot" code would get run. > > > But assuming that's OK, one naive strategy would be to just call the > > function(s) at top level in some module that gets imported by your > > app. > > Good enough? > > > On Aug 17, 9:12 am, Mathieu Leduc-Hamel wrote: > > > Tang, > > > > do you mean : > > > > "How to execute some pieces of code when you launch the "runserver" > > command > > > by example" ? If this is what you mean, it's not a easy thing to do right > > > now. Then only way i found it possible is by using: twod.wsgi > > > > With twod.wsgi you can use the entry points system of python and do, like > > in > > > Pylons, an entry defined by Paster "app_factory" > > > > You can see an example there: > >http://packages.python.org/twod.wsgi/manual/paste-factory.html#using-... > > > > mathieu > > > > On Tue, Aug 17, 2010 at 2:45 PM, Emily Rodgers < > > emily.kate.rodg...@gmail.com > > > > > wrote: > > > > On Aug 17, 2:26 am, Tang Daogang wrote: > > > > > Dear all, > > > > > > Recently, I have developed a plugin system for my app, and I want to > > > > > register those plugins when my app boot up, this need to execute some > > > > > user defined codes (functions) in app boot procedure, I don't know > > > > > where insert my registering codes to, anyone can help? > > > > > > Thank you. > > > > > Hi, > > > > > I don't know how to help you, but I think it is because you haven't > > > > explained what you want to do thoroughly enough. > > > > > What do you mean by a plugin system, and what do you mean by > > > > registering them with the app on boot up? Are you talking about > > > > including another python module in your code? Or perhaps including > > > > another django app in your code? > > > > > Can you give us a bit more information (and maybe examples) of what > > > > you are trying to do. > > > > > Cheers, > > > > Em > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Django users" group. > > > > To post to this group, send email to django-us...@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > django-users+unsubscr...@googlegroups.com > > > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/django-users?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com > > . > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en.- 隐藏被引用文字 - > > - 显示引用的文字 - -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to execute some user defined codes (functions) when Django boot?
hi, Emily, Let me introduce Scala/Lift as example. Every lift project has a file named 'Boot.scala', this file will only be executed once when this project boots up. In this file, we can write some initial codes to initial project and some userdefined structures. Emm, that's it. I want to find one file acting like Boot.scala of Lift within Django, but failed. If there is one file like that, I will put my plugins registering codes into it, thus, when I type "python manage.py runserver", it can be executed automatically and only once. By it, my plugins can be registered when app boot up. Do you understand my meaning? Welcome suggestion. On 8月17日, 下午8时45分, Emily Rodgers wrote: > On Aug 17, 2:26 am, Tang Daogang wrote: > > > Dear all, > > > Recently, I have developed a plugin system for my app, and I want to > > register those plugins when my app boot up, this need to execute some > > user defined codes (functions) in app boot procedure, I don't know > > where insert my registering codes to, anyone can help? > > > Thank you. > > Hi, > > I don't know how to help you, but I think it is because you haven't > explained what you want to do thoroughly enough. > > What do you mean by a plugin system, and what do you mean by > registering them with the app on boot up? Are you talking about > including another python module in your code? Or perhaps including > another django app in your code? > > Can you give us a bit more information (and maybe examples) of what > you are trying to do. > > Cheers, > Em -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to execute some user defined codes (functions) when Django boot?
Mathieu, Thanks for you continuous attention. I will try twod.wsgi as a scheme later. On 8月18日, 下午4时31分, Mathieu Leduc-Hamel wrote: > Richard, > > it's not the good way to do this, in the settings.py cause as i said before, > the code in the settings.py is executed every time somebody initiate a > session for the first time. The point there is a way to have a part of code > common to all currently connected user. > > Tang, > > I'm not an expert of the middleware development in Django but from what i > saw in the documentation it could be a great way to do that. Look at this > comment by example: > > "For performance reasons, middleware classes are only instantiated *once* in > long-running server processes; this means that you can't count on > __init__ getting > called every time a request runs, only once at server startup. > " > " > > -http://www.djangobook.com/en/beta/chapter16/ > > You'll need to test if it's true but there's a great possibility it would be > the case in real world experimentation. > > But if i was you i would really try twod.wsgi cause this guy is using > something that have bean used from time to time in the Pylons world where > this kind of use case is perfectly solvable. > > 2010/8/18 Richard Colley > > > > > Why not call your "boot" code from settings.py? > > > On Aug 18, 4:05 pm, Tang Daogang wrote: > > > hi, Emily, > > > > Let me introduce Scala/Lift as example. > > > > Every lift project has a file named 'Boot.scala', this file will only > > > be executed once when this project boots up. In this file, we can > > > write some initial codes to initial project and some userdefined > > > structures. > > > > Emm, that's it. I want to find one file acting like Boot.scala of Lift > > > within Django, but failed. If there is one file like that, I will put > > > my plugins registering codes into it, thus, when I type "python > > > manage.py runserver", it can be executed automatically and only once. > > > By it, my plugins can be registered when app boot up. > > > > Do you understand my meaning? Welcome suggestion. > > > > On 8月17日, 下午8时45分, Emily Rodgers wrote: > > > > > On Aug 17, 2:26 am, Tang Daogang wrote: > > > > > > Dear all, > > > > > > Recently, I have developed a plugin system for my app, and I want to > > > > > register those plugins when my app boot up, this need to execute some > > > > > user defined codes (functions) in app boot procedure, I don't know > > > > > where insert my registering codes to, anyone can help? > > > > > > Thank you. > > > > > Hi, > > > > > I don't know how to help you, but I think it is because you haven't > > > > explained what you want to do thoroughly enough. > > > > > What do you mean by a plugin system, and what do you mean by > > > > registering them with the app on boot up? Are you talking about > > > > including another python module in your code? Or perhaps including > > > > another django app in your code? > > > > > Can you give us a bit more information (and maybe examples) of what > > > > you are trying to do. > > > > > Cheers, > > > > Em > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com > > . > > For more options, visit this group at > >http://groups.google.com/group/django-users?hl=en.- 隐藏被引用文字 - > > - 显示引用的文字 - -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to execute some user defined codes (functions) when Django boot?
Sounds good idea. I'll try it. On 8月18日, 下午3时04分, Richard Colley wrote: > Why not call your "boot" code from settings.py? > > On Aug 18, 4:05 pm, Tang Daogang wrote: > > > > > hi, Emily, > > > Let me introduce Scala/Lift as example. > > > Every lift project has a file named 'Boot.scala', this file will only > > be executed once when this project boots up. In this file, we can > > write some initial codes to initial project and some userdefined > > structures. > > > Emm, that's it. I want to find one file acting like Boot.scala of Lift > > within Django, but failed. If there is one file like that, I will put > > my plugins registering codes into it, thus, when I type "python > > manage.py runserver", it can be executed automatically and only once. > > By it, my plugins can be registered when app boot up. > > > Do you understand my meaning? Welcome suggestion. > > > On 8月17日, 下午8时45分, Emily Rodgers wrote: > > > > On Aug 17, 2:26 am, Tang Daogang wrote: > > > > > Dear all, > > > > > Recently, I have developed a plugin system for my app, and I want to > > > > register those plugins when my app boot up, this need to execute some > > > > user defined codes (functions) in app boot procedure, I don't know > > > > where insert my registering codes to, anyone can help? > > > > > Thank you. > > > > Hi, > > > > I don't know how to help you, but I think it is because you haven't > > > explained what you want to do thoroughly enough. > > > > What do you mean by a plugin system, and what do you mean by > > > registering them with the app on boot up? Are you talking about > > > including another python module in your code? Or perhaps including > > > another django app in your code? > > > > Can you give us a bit more information (and maybe examples) of what > > > you are trying to do. > > > > Cheers, > > > Em- 隐藏被引用文字 - > > - 显示引用的文字 - -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to execute some user defined codes (functions) when Django boot?
Hi, Emily, I am very glad to share my design with all, but I want to show it when it can work. So let me inspect it for more days, I will introduce my design for you later. Thanks for your careness. On 8月18日, 下午6时18分, Emily Rodgers wrote: > Hi, > > I still don't really understand what you are trying to do, but it > sounds like Mathieu does and has offered you some pretty useful > advice. > > If his link below helps you fix what you are trying to do, please let > us know what you did (this is really useful for others with the same > problem), and if not, please come back and ask again. > > Em > > On Aug 18, 7:05 am, Tang Daogang wrote: > > > > > hi, Emily, > > > Let me introduce Scala/Lift as example. > > > Every lift project has a file named 'Boot.scala', this file will only > > be executed once when this project boots up. In this file, we can > > write some initial codes to initial project and some userdefined > > structures. > > > Emm, that's it. I want to find one file acting like Boot.scala of Lift > > within Django, but failed. If there is one file like that, I will put > > my plugins registering codes into it, thus, when I type "python > > manage.py runserver", it can be executed automatically and only once. > > By it, my plugins can be registered when app boot up. > > > Do you understand my meaning? Welcome suggestion. > > > On 8月17日, 下午8时45分, Emily Rodgers wrote: > > > > On Aug 17, 2:26 am, Tang Daogang wrote: > > > > > Dear all, > > > > > Recently, I have developed a plugin system for my app, and I want to > > > > register those plugins when my app boot up, this need to execute some > > > > user defined codes (functions) in app boot procedure, I don't know > > > > where insert my registering codes to, anyone can help? > > > > > Thank you. > > > > Hi, > > > > I don't know how to help you, but I think it is because you haven't > > > explained what you want to do thoroughly enough. > > > > What do you mean by a plugin system, and what do you mean by > > > registering them with the app on boot up? Are you talking about > > > including another python module in your code? Or perhaps including > > > another django app in your code? > > > > Can you give us a bit more information (and maybe examples) of what > > > you are trying to do. > > > > Cheers, > > > Em- 隐藏被引用文字 - > > - 显示引用的文字 - -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to execute some user defined codes (functions) when Django boot?
Hi, Emily, I am very glad to share my design with all, but I want to show it when it can work. So let me inspect it for more days, I will introduce my design for you later. Thanks for your careness. On 8月18日, 下午6时18分, Emily Rodgers wrote: > Hi, > > I still don't really understand what you are trying to do, but it > sounds like Mathieu does and has offered you some pretty useful > advice. > > If his link below helps you fix what you are trying to do, please let > us know what you did (this is really useful for others with the same > problem), and if not, please come back and ask again. > > Em > > On Aug 18, 7:05 am, Tang Daogang wrote: > > > > > hi, Emily, > > > Let me introduce Scala/Lift as example. > > > Every lift project has a file named 'Boot.scala', this file will only > > be executed once when this project boots up. In this file, we can > > write some initial codes to initial project and some userdefined > > structures. > > > Emm, that's it. I want to find one file acting like Boot.scala of Lift > > within Django, but failed. If there is one file like that, I will put > > my plugins registering codes into it, thus, when I type "python > > manage.py runserver", it can be executed automatically and only once. > > By it, my plugins can be registered when app boot up. > > > Do you understand my meaning? Welcome suggestion. > > > On 8月17日, 下午8时45分, Emily Rodgers wrote: > > > > On Aug 17, 2:26 am, Tang Daogang wrote: > > > > > Dear all, > > > > > Recently, I have developed a plugin system for my app, and I want to > > > > register those plugins when my app boot up, this need to execute some > > > > user defined codes (functions) in app boot procedure, I don't know > > > > where insert my registering codes to, anyone can help? > > > > > Thank you. > > > > Hi, > > > > I don't know how to help you, but I think it is because you haven't > > > explained what you want to do thoroughly enough. > > > > What do you mean by a plugin system, and what do you mean by > > > registering them with the app on boot up? Are you talking about > > > including another python module in your code? Or perhaps including > > > another django app in your code? > > > > Can you give us a bit more information (and maybe examples) of what > > > you are trying to do. > > > > Cheers, > > > Em- 隐藏被引用文字 - > > - 显示引用的文字 - -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to execute some user defined codes (functions) when Django boot?
Emm, this may another way to reach it, I'll consider it. On 8月18日, 下午10时06分, skyjur wrote: > You could try to create an app with models.py file and put your calls > in models.py. Then register your app in installed apps, above all > other apps. > > source:http://stackoverflow.com/questions/2610088/can-djangos-auth-user-user... > > On Aug 18, 1:18 pm, Emily Rodgers > wrote: > > > > > Hi, > > > I still don't really understand what you are trying to do, but it > > sounds like Mathieu does and has offered you some pretty useful > > advice. > > > If his link below helps you fix what you are trying to do, please let > > us know what you did (this is really useful for others with the same > > problem), and if not, please come back and ask again. > > > Em > > > On Aug 18, 7:05 am, Tang Daogang wrote: > > > > hi, Emily, > > > > Let me introduce Scala/Lift as example. > > > > Every lift project has a file named 'Boot.scala', this file will only > > > be executed once when this project boots up. In this file, we can > > > write some initial codes to initial project and some userdefined > > > structures. > > > > Emm, that's it. I want to find one file acting like Boot.scala of Lift > > > within Django, but failed. If there is one file like that, I will put > > > my plugins registering codes into it, thus, when I type "python > > > manage.py runserver", it can be executed automatically and only once. > > > By it, my plugins can be registered when app boot up. > > > > Do you understand my meaning? Welcome suggestion. > > > > On 8月17日, 下午8时45分, Emily Rodgers wrote: > > > > > On Aug 17, 2:26 am, Tang Daogang wrote: > > > > > > Dear all, > > > > > > Recently, I have developed a plugin system for my app, and I want to > > > > > register those plugins when my app boot up, this need to execute some > > > > > user defined codes (functions) in app boot procedure, I don't know > > > > > where insert my registering codes to, anyone can help? > > > > > > Thank you. > > > > > Hi, > > > > > I don't know how to help you, but I think it is because you haven't > > > > explained what you want to do thoroughly enough. > > > > > What do you mean by a plugin system, and what do you mean by > > > > registering them with the app on boot up? Are you talking about > > > > including another python module in your code? Or perhaps including > > > > another django app in your code? > > > > > Can you give us a bit more information (and maybe examples) of what > > > > you are trying to do. > > > > > Cheers, > > > > Em- 隐藏被引用文字 - > > - 显示引用的文字 - -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: How to execute some user defined codes (functions) when Django boot?
Dear Daniel, I must admit that I am a fresh man in Django developement, so there's indeed many concepts and procedures not clear to me, I was affected by J2EE's concepts heavily. I am ready to inspect which.py files will be executed automatically when an app start up, till now what I know are 'settings.py', 'models.py', urls.py', 'admin.py'. I will dive into it now. If you have any matierials or advices on it, please share them to me. Later I will give out my code here. Thank you. On 8月18日, 下午10时24分, Daniel Roseman wrote: > On Aug 18, 7:05 am, Tang Daogang wrote: > > > > > > > hi, Emily, > > > Let me introduce Scala/Lift as example. > > > Every lift project has a file named 'Boot.scala', this file will only > > be executed once when this project boots up. In this file, we can > > write some initial codes to initial project and some userdefined > > structures. > > > Emm, that's it. I want to find one file acting like Boot.scala of Lift > > within Django, but failed. If there is one file like that, I will put > > my plugins registering codes into it, thus, when I type "python > > manage.py runserver", it can be executed automatically and only once. > > By it, my plugins can be registered when app boot up. > > > Do you understand my meaning? Welcome suggestion. > > But you still haven't understood that a Django website served by eg > Apache is different from a standalone single-process application like > your Scala example. There's simply no such thing as 'at bootup', > because Apache will dynamically create and kill processes as required > by website load. In many configurations, those processes are > independent and do not share state with each other. > > So, do you really want something that is only run once - by the > initial process that is created on server startup? If so, any in- > memory structures that it creates would not be accessible by other > processes that are started later. This might be what you want if the > data is persisted to disk or the database, so you really do only want > it created once. > > Or, do you want a process to set up in-memory structures for itself > when it starts, which then persist inside that process for the > duration of that process? In which case, you might try putting > something into urls.py so it is run when that module is imported, > which is the way that the admin is set up via admin.autodiscover(). > -- > DR.- 隐藏被引用文字 - > > - 显示引用的文字 - -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.