How to livereload Django templates?

懵懂的女人 提交于 2020-08-01 09:50:38

问题


How can I livereload Django templates?


回答1:


I maintain the package django-livereload-server that adds both the livereload javascript and provides a livereload server in an easy django way. All you need to do is:

  • pip install django-livereload-server
  • add 'livereload' to INSTALLED_APPS
  • add 'livereload.middleware.LiveReloadScript' to MIDDLEWARE_CLASSES
  • start the livereload server/file watcher with ./manage.py livereload.



回答2:


I found a Python native solution which is easy to setup and works well, Python LiveReload (doc).

pip install livereload
livereload /path/to/monitor

You still have to install the browser plugin. The plugin and LiveReload use port 35729 to talk (customizable), but you need to point the browser to the port specified via runserver. For example:

python manage.py runserver example.com:8000

In this case the live reloaded url is http://example.com:8000, and when you change your templates the page is refreshed automatically.

As a final note, Python live reload can also be used programmatically and supports wsgi applications.




回答3:


I found a very simple solution by using Grunt and a livereload browser extension.




回答4:


You can use python-livereload like this:

pip install livereload
livereload project/static

And in order to make this work add this snippet into your base.html:

<script type="text/javascript" src="http://127.0.0.1:35729/livereload.js"></script>

Then run ./manage.py runserver and it should work.



来源:https://stackoverflow.com/questions/19073878/how-to-livereload-django-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!