Django - Apply changes in HTML & Static files without restarting dev server - python

I am working in a dev environment using the built in Django web server. One of the inconvenience that I have is everytime I make changes in HTML or Static files it does not apply when I reload the browser until I kill the dev server and run again.
python manage.py runserver localhost:8000
Is there a way so Django will reflect the changes instantly? Thanks in advance

Django reload the server only on changes on .py files. I read different ways to trigger reloading (such as installing a third party app, tweaking caching depending on whether DEBUG = True, etc etc).
The easiest and dumbest way is to make an insignificant slight change in the view you're working on (say, adding a #, removing it) after you edited and saved your template. It is dumb but it works.

Related

Deploying static files for a Wagtail application on Divio

I'm struggling to understand how I can implement my static files live. This is my first project I'm trying to deploy so it's possible I've missed something, and I'm finding it hard to understand which documentation is best to follow here - Wagtail, Divio or Django?
I can view my website with the localhost fine, the static files are read. But when deploying to Divio’s test servers, no longer, just Bootstrap stylings. Am i meant to set debug to False somewhere, and if so where do I set it so?
The dockerfile in the Divio project contains this command, which I sense is related to deploying live:
# <STATIC>
RUN DJANGO_MODE=build python manage.py collectstatic --noinput
# </STATIC>
What are the steps needed to transition from operating on the localhost and viewing my static correctly, to having it display in test/live deployments?
I thought I could link them with the settings.py file but when I try to do this I experience a problem related to the following step:
Step 7/7 : RUN DJANGO MODE=build python manage.py collectstatic —noinput
It seems to hang almost indefinitely, failing after a long time - the following are the last few lines of my logs.
Copying '/virtualenv/lib/python3.5/site-packages/wagtail/admin/static/wagtailadmin/fonts/opensans-regular.woff'
Copying '/virtualenv/lib/python3.5/site-packages/wagtail/admin/static/wagtailadmin/fonts/wagtail.svg'
Copying '/virtualenv/lib/python3.5/site-packages/wagtail/admin/static/wagtailadmin/fonts/robotoslab-regular.woff'
Copying '/virtualenv/lib/python3.5/site-packages/wagtail/admin/static/wagtailadmin/fonts/opensans-semibold.woff'
Thanks all in advance for your time and help!
In a Divio Cloud project, the settings for things like static files handling and DEBUG are managed automatically according to the server environment (Live, Test or Local).
See the table in How to run a local project in live configuration. You can override these manually if you need to, but there is no need whatsoever in normal use.
If you have added settings related to static file handling to your settings.py, try commenting them out - almost certainly, it will just work.

Web.py reload development server while code was changed

i'm working on web.py project with separated code in different files
- urls.py for urls,
- views.py for controllers,
- server.py for describing my application and it's option.
But i got a big problem - i need to restart my server (python server.py) every time when code was changed.
it makes me crazy.
I've tried 'touch server.py' and all other project files, tried to remove all *.pyc from project but without restart server code not updated.
May be someone knows how to fix this and save time?
Thanks!
http://webpy.org/docs/0.3/tutorial#developing states:
web.py also has a few tools to help us with debugging. When running with the built-in webserver, it starts the application in debug mode. In debug mode any changes to code and templates are automatically reloaded and error messages will have more helpful information.
The debug is not enabled when the application is run in a real webserver. If you want to disable the debug mode, you can do so by adding the following line before creating your application/templates.
web.config.debug = False
Are you using the internal webserver or an external one?

Django same project multiple times on one server

I had to develop something in Django (new to it) and it went quite smoothly. But after delivering to the client I had to setup a second "testing" instance so that any new features would be tested on it to avoid errors in the production one.
And I have only one apache server at my disposal and this breed some weird things.
I run my applications by adding path to the wsgi script in the httpd.conf.
It works fine, the new server is up and running. it used a different database so all is good. But it doesent use the views and models from its folder, it used the ones from the original app instead and I just ran out of ideas on how to fix it. Please help me in some way.
I believe that your two django projects should be deployed on your staging and production server as two completely seperate projects/directories.
If you use version control, this could be as trivial as branching your main project and adding the new features. After you have two seperate code bases you can put your fixed branch on your production server.
Your project can exist anywhere on your server. You could set up a staging subdomain and create a virtualhost that points to your django project branch
http://httpd.apache.org/docs/2.2/vhosts/examples.html
This would allow both projects to exist on the same server, without one project having to be aware of the other

How can I make the locally running GAE dev server auto-detect changes to templates?

I notice that whenever I make a change to one of my gae project python files, my changes automatically impact my locally running development server. However, whenever I make a change to one of my Mako templates, google app engine does not automatically detect it, and I have to restart the local development server manually for the change to take effect. As you can imagine, this makes editing UI elements tedious. Is there any way I can make gae auto-detect changes to my templates?

How to make web2py dev server track file changes and restart automatically?

I used to work with Django and the way it's runserver restarts automatically whenever some python file is changed. That is really convenient and makes development easier for me.
Is there some way to tell web2py development server to track changes in python files and restart automatically?
Any help is appreciated.
This is much easier in web2py and happens automatically. web2py model, controller, and view files are executed in a prepared environment on every request, so any updates to those files are reflected immediately without restarting anything. For modules that you import, you can do the following (typically in a model file):
from gluon.custom_import import track_changes
track_changes(True)
Any module that has changed since the last import will be reloaded.

Categories