Creating a new Django Project with Eclipse Py-Dev

Info This post has , please enjoy the discussion !

The Django tutorial  is very well written and so is the PyDev page about it . However I have to say I would have appreciated a tutorial showing how to replicate the Django tutorial in  PyDev. As I could not find it I decided to write one myself.

I assume you have already installed the PyDev plugins. If so you can create a new project in the workspace  (right click->New->Other) and select PyDev Diango Project


djangotut1shot0

Choose the Project name and press Next

djangotut_shot

Then Choose the Database Engine you want to use (in this example sqlite3)

djangotut1shot_01

you can therefore try to run the project. The following picture depicts the output you are supposed to get in the Console.

djangotut1_shot02

If you then open a browser and go on http://127.0.0.1:8000 you should get the example webpage depicted in the following picture

djangotut1_shot03

Contratulations! Your configuration works fine!

Now first of all you have to start a new app (se the Django tutorial for further details). To do this in PyDev you just have to right click on the project; choose the Django menu and the  custom command sub-menu.

shot1

This will open the pop-up depicted above where you can add the command you want to execute. Once finished it will be as if you executed the command after the manage.py script in the ordinary Python shell.

shot2

Here is how the Django project should look like after you created the testApp.

shot3

Now go in the url.py file and uncomment the admin url

shot4

go in the testApp/models.py and create a simple data model for your app. I have defined the same model used in the Django tutorial.

shot5

You know have Django to synchronize the app’s db with the data-model. To this end create a new command name syncdb and execute it. PyDev will execute such command after manage.py as you would do in the orinary Django shell.

shot6

You can see in the following figure the output of the Console you will get when executing syncdb.

The first time you will be asked to create a new super user. Do that so type yes.

shot7

To create a super user you’ll have to specify some parameters such as username, email and password.

shot8

Now you have to go in the settings.py file of your Django project and add your new app in the INSTALLED_APPS list as you can see depicted in the following picture.

shot9

Run the project again and go o the admin page you just created http://127.0.0.1/admin

shot10

Here is how the admin login page looks like

shot12

authenticate as super user

shot13

and this his how the page appears once you authenticated. As you can see it just allows you to add new users. This is because we did not registered the new app data model to the administration service.

shot14

To this end go in the app package and create a new PyDev module named  admin.py.

shot15

Inside that use the admin object, imported from django.contrib, to register the elements of your data model you want to manage in the admin page

shot16

remember to execute the syncdb command and go to the admin page. This time the app’s data model elements should be available

shot17

you can add new, or change already existing, instances of these data.

shot18

In order to open the Django shell right click on the project, choose Django and choose ‘Shell with Django Environment’

shot19

It will run the related Console as depicted in the following figure

djangotut1shot_04

here you can import Classes from your models, create instances, assign values to their properties and save them.

djangotut1shot_05

Changes will be reflected in the database and will be shown in the administration page

djangotut1shot_06

Now you have managed to run Django in Eclipse check out our other posts about Django:

  1. User Authentication in Django

Heads Up!

If you have found this post useful please consider to share it with your friends

and to reccomend it on Google

thank you !!!

blog comments powered by Disqus