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?
Related
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.
I'm used to building my websites with PHP, and on my OS X machine I expect to have to ensure that I have my scripts living in an explicitly specified location that I define as my Apache server's document root. But when I follow the simple instructions for building a Flask website, I magically get a working website, with nothing at all in any of the places on my machine that serve as document roots, regardless of where I have my Flask script. This is especially confusing since I always think if deployment as involving careful duplicating the file structure of my site under document root on the deployment server's document root.
Where is Flask "running from" on my OS X machine? Where do I "put it" when I deploy it (and what to I put)?
It's running from wherever you put it. You surely know where you saved the code: that's where it is.
But your mistake is in thinking that this development environment is running through Apache, or indeed has anything to do with how you'll run it in production. Neither is true. You're using a development server, the separate Werkzeug project, but that is not suitable for running in prod.
When you are ready to deploy, Flask has full instructions on how to either connect it to Apache through mod_wsgi, or set up a separate WSGI server which you'll usually connect to through a reverse proxy such as nginx.
Supposed you have your main.py under /path/to/my_project/, when you run the internal server python main.py, Flask is then running under your project folder.
Of course that built-in server is only good for development, when you're trying to deploy for production, normally Gunicorn (via wsgi app, read more HERE) or other web server is more appropriated (and advised by Flask) itself. And your production folder can be placed wherever you want, just like Apache PHP you may place your folder under /var/www/ (EDITED: as Daniel Roseman pointed out, you may try to change this folder location for security concern), it's the same for Flask, that's nothing stops you placing the folder but rather have the permission set properly.
Hope this helps.
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.
So, I'm running Apache2 on a Linux machine, and I'm trying to serve pages with Django 1.3. I found a guide to do this here.
I have the django.wsgi configured, the settings.py configured, and the database created and successfully in sync with Django. However, when I try to visit the website, I am shown a page served by Apache, instead of Django. I get no errors/warnings at all.
I put print statements in both django.wsgi and settings.py (since they're both just python files), but nothing gets printed.
Does anyone have any idea as to what may be going wrong or any diagnostic steps I might be able to take?
Thanks!
As everyone has said in the comments, you need to add a WSGIServerAlias directive to the Apache configuration before anything will work. Otherwise, Apache can't possibly know to use WSGI to serve your site.
I'm running mod_wsgi on apache2. It's running Django and for some reason, after I change my code, old versions are sometimes shown along with new code.
For example, after creating a view that simply returns an Http Response with "Hi", I get either the Django start page or "Hi".
Any ideas what would cause this?
Thanks.
As #aaronasterling said - mod_wsgi keeps code loaded however there is no need to restart apache after change. More convenient way is to touch wsgi file from CLI, e.g.:
$ touch django.wsgi
apache2/mod_wsgi keeps parts of the application loaded between requests. You have to restart the server after code updates.
This could possibly be your browser caching responses from the server. Try disabling caching to see if that has any affect. Even if it doesn't now, doing so can potentially save you a lot of grief and confusion in the future.
Delete any .pyc files from your code base directory, and restart the server.