3

I using Eclipse with PyDev to develop Django Webapplication. I can start my webserver with

python manage.py runserver

and then I can test my webapplication locally in my browser. However everytime I change the sourcecode I have to restart eclipse so that these changes get applied in my webapplication.

I guess I have to somehow restart the webserver so that my sourceode gets interpreted again so that my changes get applied. But how do I do that? I couldnt find any command to do so.

Pascal Klein
  • 23,665
  • 24
  • 82
  • 119

2 Answers2

6

Django dev server restarts it self when python code changes. This may not happed if you run it with noreload option

./manage.py runserver --noreload

Another case when the server is not reloaded automatically is when the files changes is not used by django. For example if you have syntax error in your admin.py django won't use it. And changing it won't restart the server. Have in mind that if you use eclipse debug you will have to run django with noreload because of an bug that does not relaunch the instance but starts a new one.

Ilian Iliev
  • 3,217
  • 4
  • 26
  • 51
2

First, configure the project as a django project in eclipse, if not already so. (Right click on the project, and select PyDev -> Set as Django Project).

Second, click on the green run button at the top, and select "run configurations". Select the PyDev Django icon and hit the new launch configuration button at the top. Enter the project name, (let's say testproject), and "${workspace_loc:testproject}/${DJANGO_MANAGE_LOCATION}" for the main module.

On the Arugments tab, enter "runserver 0.0.0.0:8000 --noreload" if you want to your server to be visible for machines outside yours, or "runserver --noreload" if you want access on your machine only, and change the working directory to "${workspace_loc:}".

Click apply and you should be set to go!

Here's what it should look like when running inside of eclipse: enter image description here

Adam Morris
  • 8,265
  • 12
  • 45
  • 68
  • You are telling me I should pass '--noreaload', but llian lliev says the exact opposite! Or am I getting something wront here? – Pascal Klein Aug 05 '11 at 10:58
  • 1
    When you are running inside of eclipse as a pydev run configuration, you need "--noreload", because when the runserver otherwise runs in autoreload mode it starts another process that pydev can't control (and won't catch the output in the console window). – Adam Morris Aug 05 '11 at 11:05
  • 1
    This does mean, that when you make changes, you relaunch within eclipse (hit the red square). You should see the app running in the console window. – Adam Morris Aug 05 '11 at 11:12
  • Thanks for your last comment: I just had to click the red "terminate" Button!!!! Then Run again and my new sourcecode gets applied to my app! Thanks a lot. – Pascal Klein Aug 05 '11 at 17:15
  • The --noreload option should be used only when in debug mode. The problem with the separate process run the Adam mentioned appeared only if you are not running it in debug mode. In normal mode it is ok to have it without noreload. Off topic: using dev server to serve all things(django and media) is really slow, I propose to you to use real web server for serving the media files. – Ilian Iliev Aug 19 '11 at 07:12