Working with Django and Eclipse.

Before going further on the development of our RSS reader app, lets just have a quick look about the how to work on the project with Eclipse. Actually, if you are planning to dedicate your life to Python and web development, Aptana Studio is certainly a better choice as it is an Eclipse ready to use. But if you want to build your own IDE with the plug-ins of your choice, you’ll certainly use Eclipse. But Eclipse does not support Python out of the box. As I introduced the tools in the first post of this tutorial, you’ll need to add the PyDev plug-in which will give you all the features you need. The manual and especially the Getting Started chapter provides a good explanation about how to configure the plug-in.

The manual also explains how to create a new project and how to import one. There is also a specific page for Django. If you followed the previous step of the tutorial, you already have created the project sources and you’ll need to import them. To understand why and how, lets just see how you would have done directly from Eclipse.

So, instead of executing the command

django-admin.py startproject myprivatesite

create a new project from Eclipse using the standard way and choose a Django project.

django_eclipse_creating_new_project1

Then you will have to set the project name and its location.

django_eclipse_creating_new_project2Beware, the directory entry in the capture above should be the root directory of the project. This mean that the capture above will create the manage.py file and the myprivatesite package in the workspace directory.

The last frame will ask you for the database configuration. Enter there all the informations you would have provided in the settings file. The wizard will create a settings file all setup.

django_eclipse_creating_new_project3Now, you are ready to create the app. Eclipse does not provide any tool to create an application. But now, you can use the command line. So, lets execute the startapp command

python manage.py startapp reader

Make sure to be on the root of your project working tree when you execute this last command. You will then need to refresh the project in Eclipse and the package will appear.

So, the best way to work on a Django project in Eclipse is to create the project using Eclipse. This is the easiest way to do it because Eclipse need some configuration files (the famous .project) and creating the project trough Eclipse will create those files. As the other commands does not affect those files, you can (and must) use them from the command line.

But what if you have already created the project outside Eclipse ? You can follow the PyDev manual, of course. Another way is to remember that a project contains only packages. So, even if you have created a project, create a new one in Eclipse. Then, simply replace its content by the one you have previously made, keep the .project file, of course.

But you have a third option: don’t create a Django project in Eclipse. Remember that applications are standard Python packages with their content following some conventions. This means that you can import those packages like any other Python package. You can work on your application and leave the Django project outside Eclipse. Keep in mind that Django is designed for modularity, so choose the best way to work for you.

Finally, I really invite you read the Django page of the PyDev manual. You may find it useful to launch Django commands from Eclipse or use the embedded interactive shell.

About Darko Stankovski

Darko Stankovski is the founder and editor of Dad 3.0. You can find more about him trough the following links.

Darko Stankovski

Darko Stankovski is the founder and editor of Dad 3.0. You can find more about him trough the following links.

You may also like...

Leave a Reply