Sorry, I'm newbie on python.
I change code in .py file but no changes happens.
Guess, script code is cahced in memory.
What should I do to make my changes working?
PS: tried to delete complied .pyc file, no luck 8-(
guess, IO need to try to restart uwsgi/nginx?
Older versions of django
find . -name "*.pyc" -exec rm -rf {} \;
New version of django has this:
python manage.py clean_pyc
If you simply want to restart the webserver it depends on the configuration you are using:
via gunicorn:
use --reload option
via django inbuilt runserver:
since version 1.7 it automatically does that.
Just touch the WSGI file: touch wsgi.py and your project should refresh.
Please have a look at this similar request: How to reload new update in Django project with Apache, mod_wsgi?
Related
I'm trying to use Heroku buildpacks to allow me to run PhantomJS from a Flask app. I've tried to follow the advice here and after I add the buildpacks and push, I still only see heroku/python when I check with heroku buidpacks at the command line.
After some research it seemed maybe multiple buildpacks is not supported and I needed to try what this site recommended. I added the
$ heroku config:
add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
created the .buildpacks file in the project root with the following:
https://github.com/heroku/heroku-buildpack-python
https://github.com/stomita/heroku-buildpack-phantomjs
and modified the path, as recommended:
$ heroku config:add LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib:/app/vendor/phantomjs/lib
after pushing, still I see only heroku/python when i try heroku buildpacks.
Also, for what it's worth the below test doesn't work for me, because there is no vendor directory. I'm not sure where that directory even comes from, but it was never in my project, so I can only assume that the buildpacks are suppose to create it? I found countless references to this directory, and adding this directory to the Heroku path, but not a single one explained it's origin, other than to say that is where the phantomJS buidpack installs to
$ heroku run bash
$ vendor/phantomjs/bin/phantomjs
For anyone who gets stuck on this...
Rather than this:
$ heroku config:
add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
You actually need to do the this: (as outlined here):
$ heroku buildpacks:
set https://github.com/ddollar/heroku-buildpack-multi.git
While developing locally on a side Django project, my workflow is currently this:
Make changes.
Go to Terminal session with virtual environment. Stop foreman with ctrl+C.
Type python manage.py collectstatic to move all my static css/js/img files.
Restart foreman with foreman start.
In an attempt to be more efficient and do a better job of learning, I'm wondering how I can optimize the workflow is it's more like this:
Make changes.
Run a single command that moves static files and restarts foreman.
Would someone be able to point me in the right direction. Thanks.
You could create a bash script that does this bunch of commads for you.
While I have no experience with foreman, you could create a script with content something like:
#!/bin/bash
sudo killall foreman
python manage.py collectstatic
foreman start
Then add execution rights to it:
chmod +x script.sh
And execute everything in one command:
./script.sh
I assume you absolutely can't get around using foreman for local development, cause otherwise you would not even need to do a collectstatic or manual restart.
Maybe writting a custom management command based on runserver is the way to go for you, as it would already have the check-for-change-and-restart logic in it.
https://docs.djangoproject.com/en/dev/howto/custom-management-commands/
https://github.com/django/django/blob/master/django/core/management/commands/runserver.py?source=cc
I've finished the Heroku tutorial on how to upload and launch a basic django based web app using the following:
https://devcenter.heroku.com/articles/django#gitignore
Can anybody provide steps or a link to documentation on how to re-connect to Heroku and properly upload changes you've made to your site? Starting from a fresh terminal and cd'ing into the folder where your manage.py and procfiles live, what would the following steps be?
I then do:
$ virtualenv venv --distribute
$ source venv/bin/activate
after this i try to run $python manage.py runserver but it can't find django modules etc...
Do I need to reinstall django everytime I go to git push an update on the server?
To answer your question:
Heroku is just git, basically. At least on your computer.
So you don't need to "connect" to Heroku. You just cd to your source folder and use it as you would a normal git repository.
If you're using a virtualenv (which you should be), after you cd to your directory, you'll need to reactivate the virtualenv. If you followed heroku's Django tutorial, it'll probably be the command source venv/bin/activate
If you want to dig into some of herokus commands, download the Toolbelt.
To test whether your Procfile is working, use Honcho. It's a python version of foreman, Heroku's Ruby-based local Procfile runner.
To see which files are on your Heroku app:
Launch the bash on heroku by typing this command on your terminal:
heroku run bash --app appname
From there just ls and see your folders.
This is a weird question but its been driving me bonkers for the last 3 hours. I wanted to play around with a pyramid based cms Kotti and I made a mistake by installing it using easy_install first(sudo easy_install kotti). I'm getting weird behavior and I'm not sure if its the way the program itself or the way I installed it.
I want to change some parts of the code and see how it works but my changes are not taking effect. After I installed it via easy_install I did:
virtualenv mysite --no-site-packages
bin/easy_install pyramid
git clone https://github.com/Pylons/Kotti.git
cd Kotti
sudo ../bin/python setup.py develop
../bin/pserve app.ini --reload
I went to 127.0.0.0:5000 and saw it was working. The first page has text that says "Congratulations! You have successfully installed Kotti." so I went into the kotti directory and did a grep "Congratulations" *.* and found it was coming from populate.py. So I opened the file and changed the line to a different piece of text and saved. Because I have the --reload flag on pserve I noticed it reloaded my code on the terminal and when I went back to the site the data did not change.
I'm so confused because the server reloads when I change the python code, so it sees the change but its not reflected in the browser(just to test if its the browser cache I tried it using different browsers and cleared the cache).
Any ideas?
When you run a Kotti web application for the first time, as with most CMS systems, it runs a set of data population methods (including that populate.py code you mentioned) to set up a database and insert all the content you see. The --reload is only telling the deployment server to watch for file changes as you work on the file system.
If you want to rerun the installation/population code then you need to delete the created database. If you haven't made any changes from their example app.ini file it will likely be Kotti.db.
Alternatively use the CMS to make the changes, as is intended by the CMS systems.
Running python -v will show all the imports
I'm using Capistrano to deploy a Django application (it uses Nginx as the web server), using instructions I found at http://akashxav.com/2009/07/11/getting-django-running-on-nginx-and-fastcgi-on-prgmr/ (I had to look at a cached version earlier today) and was wondering about the last command in there, which is
python manage.py runfcgi host=127.0.0.1 port=8081 --settings=settings
I understand at a high level that this is telling the application that we want to run a few instances of the FastCGI binary to serve up this application.
What I was wondering is how is the best way to handle "resetting" this, for lack of a better word. For those who don't know, Capistrano deploys things by creating "releases" directories and then providing a symlink to the latest release.
Since I can do post-deployment tasks (I've done this with CakePHP applications to do things like properly set directory permissions for a caching directory in the application) I was wondering how to turn off the existing processes created by the command above and start up new ones.
I hope I am making sense.
There is a section in the django docs about this
Basically use the pidfile option to manage.py and then write a small shell script to use that pid to kill the existing cgi process if it exists before starting the new one.
Something like this
#!/bin/bash
if [ -f "pidfile" ]; then
kill `cat -- pidfile`
rm -f -- pidfile
fi
exec python manage.py runfcgi host=127.0.0.1 port=8081 pidfile=pidfile --settings=settings
NB FastCGI support is deprecated and will be removed in Django 1.9