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
Choose the Project name and press Next
Then Choose the Database Engine you want to use (in this example sqlite3)
you can therefore try to run the project. The following picture depicts the output you are supposed to get in the Console.
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
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.
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.
Here is how the Django project should look like after you created the testApp.
Now go in the url.py file and uncomment the admin url
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.
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.
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.
To create a super user you’ll have to specify some parameters such as username, email and password.
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.
Run the project again and go o the admin page you just created http://127.0.0.1:8000/admin
Here is how the admin login page looks like
authenticate as super user
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.
To this end go in the app package and create a new PyDev module named admin.py.
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
remember to execute the syncdb command and go to the admin page. This time the app’s data model elements should be available
you can add new, or change already existing, instances of these data.
In order to open the Django shell right click on the project, choose Django and choose ‘Shell with Django Environment’
It will run the related Console as depicted in the following figure
here you can import Classes from your models, create instances, assign values to their properties and save them.
Changes will be reflected in the database and will be shown in the administration page
Now you have managed to run Django in Eclipse check out our other posts about Django:
If you have found this post useful please consider to share it with your friends
thank you !!!