Difference between revisions of "Python-Django/C2/How-to-use-Django-Admin-app/English"
Pravin1389 (Talk | contribs) (Created page with "'''Title of script: '''How to Use Django admin app '''Keywords: '''Video tutorial, Django Admin App, Web Application Framework {| border=1 |- || Visual cue || Narration |-...") |
Nancyvarkey (Talk | contribs) |
||
Line 9: | Line 9: | ||
|- | |- | ||
|| Slide: Use Django Admin App | || Slide: Use Django Admin App | ||
− | || Hello and welcome to the spoken tutorial on “'''How to | + | || Hello and welcome to the spoken tutorial on “'''How to use Django admin app'''” |
|- | |- | ||
|| Slide: Learning Objectives | || Slide: Learning Objectives | ||
Line 15: | Line 15: | ||
* Use '''Django admin app''' | * Use '''Django admin app''' | ||
− | * Create an '''admin''' | + | * Create an '''admin user''' |
|- | |- | ||
Line 37: | Line 37: | ||
|- | |- | ||
|| Slide: What is '''Django''' Admin App? | || Slide: What is '''Django''' Admin App? | ||
− | || The '''Django admin app '''is a feature that provides an interface to | + | || The '''Django admin app '''is a feature that provides an '''interface''' to |
* Create | * Create | ||
Line 48: | Line 48: | ||
Press CTRl+ALT+T simultaneously | Press CTRl+ALT+T simultaneously | ||
− | || Let us open the '''terminal '''by pressing '''Ctrl | + | || Let us open the '''terminal '''by pressing '''Ctrl, Alt''' and '''T '''keys simultaneously on your keyboard. |
|- | |- | ||
|| [Terminal] | || [Terminal] | ||
Line 89: | Line 89: | ||
|| In our previous tutorial, we have created the '''models''' within the '''blog app.''' | || In our previous tutorial, we have created the '''models''' within the '''blog app.''' | ||
− | Now, we will use the '''Django admin | + | |
+ | Now, we will use the '''Django admin site,''' so that we can manage our '''blog website'''. | ||
|- | |- | ||
|| [Terminal] | || [Terminal] | ||
Line 135: | Line 136: | ||
'''Superuser created successfully.''' | '''Superuser created successfully.''' | ||
|| Now, the '''superuser''' has been created successfully. | || Now, the '''superuser''' has been created successfully. | ||
+ | |||
Let’s log in and take a look at what exists on our''' admin site.''' | Let’s log in and take a look at what exists on our''' admin site.''' | ||
Line 142: | Line 144: | ||
Type python manage.py runserver and press Enter | Type python manage.py runserver and press Enter | ||
|| Let's run the '''Django development server.''' | || Let's run the '''Django development server.''' | ||
+ | |||
Type '''python <space> manage dot py <space> runserver ''' | Type '''python <space> manage dot py <space> runserver ''' | ||
|- | |- | ||
− | || Open a browser and type | + | || Open a browser and type http://localhost:8000/admin |
− | || Now, open a web browser and go to | + | || Now, open a web browser and go to http://localhost:8000/admin |
|- | |- | ||
|| On browser | || On browser | ||
Line 156: | Line 159: | ||
Password as '''Sample123''' | Password as '''Sample123''' | ||
|| We can see a '''Django administration login page.''' | || We can see a '''Django administration login page.''' | ||
+ | |||
Enter the '''superuser''' credentials which we created just now. | Enter the '''superuser''' credentials which we created just now. | ||
Line 165: | Line 169: | ||
Point to '''Groups''' and '''User''' app | Point to '''Groups''' and '''User''' app | ||
|| Here we can see “'''Authentication and Authorization'''”, and its '''modules Groups''' and '''Users.''' | || Here we can see “'''Authentication and Authorization'''”, and its '''modules Groups''' and '''Users.''' | ||
+ | |||
You may notice that our '''blog app''' is still not visible in the '''admin interface.''' | You may notice that our '''blog app''' is still not visible in the '''admin interface.''' | ||
− | In order to see our '''blog app''' in our '''admin interface''', we need to register our '''blog | + | |
+ | In order to see our '''blog app''' in our '''admin interface''', we need to register our '''blog app'''. | ||
+ | |||
We have do that in the '''admin '''file of the '''app'''. | We have do that in the '''admin '''file of the '''app'''. | ||
Line 226: | Line 233: | ||
admin.site.register(Article) | admin.site.register(Article) | ||
|| This is to make our '''models''' visible on the '''admin page.''' | || This is to make our '''models''' visible on the '''admin page.''' | ||
+ | |||
We need to register the '''model''' with '''admin site dot register within parentheses modelname''' | We need to register the '''model''' with '''admin site dot register within parentheses modelname''' | ||
Line 343: | Line 351: | ||
I will fill the details as follows | I will fill the details as follows | ||
− | For '''Blog, '''select '''Blog object1 '''from the drop down. | + | *For '''Blog, '''select '''Blog object1 '''from the drop down. |
− | Then type the '''Title '''as '''My Article.''' | + | *Then type the '''Title '''as '''My Article.''' |
− | And '''Body '''as '''This is my first article.''' | + | *And '''Body '''as '''This is my first article.''' |
− | Leave the '''Draft '''as unchecked for now. | + | *Leave the '''Draft '''as unchecked for now. |
|- | |- | ||
|| Click on '''Save''' button | || Click on '''Save''' button | ||
Line 359: | Line 367: | ||
'''The article “Article Object was added successfully”''' | '''The article “Article Object was added successfully”''' | ||
− | || We see a message that the '''Article Object | + | || We see a message that the '''Article Object 1''' was added successfully. |
|- | |- | ||
Line 391: | Line 399: | ||
Hover from web app to database to and fro | Hover from web app to database to and fro | ||
− | || We see the following:* the '''user''' sends a request | + | || We see the following: |
+ | * the '''user''' sends a '''request''' | ||
* and the '''web app '''process it and sends back a '''response'''. | * and the '''web app '''process it and sends back a '''response'''. | ||
* the '''web app''' is connected to a '''database''' to store the data. | * the '''web app''' is connected to a '''database''' to store the data. | ||
Line 400: | Line 409: | ||
|| | || | ||
* '''Django''' is a '''web framework.''' | * '''Django''' is a '''web framework.''' | ||
− | * We also saw an easy interface to the '''database'''. | + | * We also saw an easy '''interface''' to the '''database'''. |
− | * '''Django '''provided the '''request '''and '''response ''' | + | * '''Django '''provided the '''request '''and '''response interface'''. |
* The other features of the '''web framework''' will be covered in the upcoming tutorials. | * The other features of the '''web framework''' will be covered in the upcoming tutorials. | ||
Line 409: | Line 418: | ||
Press Ctrl+C keys | Press Ctrl+C keys | ||
|| Let us now stop the '''server '''and deactivate the '''virtual environment.''' | || Let us now stop the '''server '''and deactivate the '''virtual environment.''' | ||
+ | |||
Switch to the '''terminal.''' | Switch to the '''terminal.''' |
Latest revision as of 18:37, 12 September 2018
Title of script: How to Use Django admin app
Keywords: Video tutorial, Django Admin App, Web Application Framework
Visual cue | Narration |
Slide: Use Django Admin App | Hello and welcome to the spoken tutorial on “How to use Django admin app” |
Slide: Learning Objectives | In this tutorial, we will learn to
|
Slide: System Requirements | To record this tutorial, I am using
However you may use any other browser and editor of your choice. |
Slide: Prerequisites | To follow this tutorial, you need to know
|
Slide: What is Django Admin App? | The Django admin app is a feature that provides an interface to
|
Open a Terminal window
Press CTRl+ALT+T simultaneously |
Let us open the terminal by pressing Ctrl, Alt and T keys simultaneously on your keyboard. |
[Terminal]
cd my-django [Enter] |
Now using cd command, go to the folder my hyphen django which we had created earlier. |
[Terminal]
Type source myapp_env/bin/activate and press Enter |
Let us activate the virtual environment myapp underscore env
Type source <space> myapp underscore env slash bin slash activate And press Enter. |
[Terminal]
cd mysite & Press Enter |
Now let us go to the mysite folder by typing
cd <space> mysite and press Enter. |
Here onwards, please remember to press the Enter key after typing each command. | |
[Terminal]
Type ls blog [Enter] |
Type ls <space> blog |
[Terminal]
Highlight models.py |
In our previous tutorial, we have created the models within the blog app.
|
[Terminal] | For this, we need to have credentials to log in.
Django provides an easy way to generate a super-user account. |
[Terminal]
Type python manage.py createsuperuser and press Enter |
Let’s create a superuser to login to the admin interface.
Type python <space> manage dot py <space> createsuperuser |
[Terminal]
Point to the Shell prompt |
We will be prompted to fill in some details.
Fill the information as per your own preferences. |
[Terminal]
Username: root Email address: stdjango@gmail.com Password: Sample123 Password(again): Sample123 |
I will type the following details.
Username as root Email address as stdjango@gmail.com Password as Sample123 Enter the same password once again. |
[Terminal]
Highlight Superuser created successfully. |
Now, the superuser has been created successfully.
|
[Terminal]
Type python manage.py runserver and press Enter |
Let's run the Django development server.
|
Open a browser and type http://localhost:8000/admin | Now, open a web browser and go to http://localhost:8000/admin |
On browser
Enter Username as root Password as Sample123 |
We can see a Django administration login page.
I will enter the username as root and password as Sample123 |
On browser
Point to Groups and User app |
Here we can see “Authentication and Authorization”, and its modules Groups and Users.
|
[Terminal]
Press Ctrl+C simultaneously |
Switch back to the terminal.
Stop the server by pressing Ctrl and C keys simultaneously. |
[Terminal]
Type gedit blog/admin.py & press Enter |
Let us open the admin.py file with any text editor.
I will be using gedit text editor. Type gedit <space> blog slash admin dot py <space> ampersand |
[admin.py]
from django.contrib import admin # Register your models here. |
We are now inside the admin.py file. |
[admin.py]
from django.contrib import admin from blog.models import Blog, Article |
Let us import our app models.
This enables the admin interface to pick the models. And then show it to the user who logs in to the admin site. |
[admin.py]
# Register your models here. admin.site.register(Blog) admin.site.register(Article) |
Below the line Register your models here, type the code as shown here. |
[admin.py]
Highlight admin.site.register(Blog) admin.site.register(Article) |
This is to make our models visible on the admin page.
|
[admin.py]
Highlight from django.contrib import admin # Register your models here. |
Note that, it already imported django.contrib.admin |
[admin.py]
Highlight import admin |
The admin class is the representation of a model in the admin interface. |
[admin.py]
Highlight from .models import Blog, Article |
We are importing our models here. |
Highlight
admin.site.register (Blog) admin.site.register (Article) |
We have now registered the Blog and Article models. |
Press Ctrl+S | Save and close the file. |
Switch to Terminal | Switch back to the terminal. |
[Terminal]
Run the server Type python manage.py runserver and press Enter |
Let's now run the Django development server.
To do that, type python <space> manage dot py <space> runserver |
Switch to browser & refresh the page
Point to Blogs and Articles |
Then switch to the browser and refresh the page.
Now, we can see our blog app and its models in the admin page. |
[On browser]
Highlight Click Add (besides Blogs) |
Let us now add a blog.
Click on the Add link next to Blogs. |
[On browser]
Add blog Name: My First Blog |
Let’s fill the form for a New Blog.
I will enter the Name as My First Blog. |
[On browser]
(Pointing cursor on the web page) |
Note that the created_on field is not shown here.
As per our model definition, it will be auto added by Django. |
Click on Save button | Click on the Save button to submit the form. |
[On browser]
Highlight The blog “Blog Object(1) was added successfully” |
We get a message that the Blog Object has been added successfully. |
[On browser]
Click on Home |
Let us go back to the admin’s home page.
To do that, go to the top left and click on the link Home. |
[On browser]
Click on Add (besides Articles) |
Let us now add an Article to our blog app.
Click on the Add link next to Articles. |
[On browser]
Blog:Blog object1 Title:My Article Body:Article object |
Let’s fill the form for New Article.
I will fill the details as follows
|
Click on Save button | Click on Save button to submit the form. |
[On browser]
Highlight The article “Article Object was added successfully” |
We see a message that the Article Object 1 was added successfully. |
[On browser]
Click on Home |
Let us go back to the admin’s home page.
Go to the top left and click on the link Home. |
[On browser] | You can click on the blog and article created, to view or edit or delete. |
[On browser] | At the top right corner, click on the LOG OUT link to logout from the admin’s interface. |
Switch to Slide from browser | We have successfully added database entries for our models. |
Slide:
Image of web application from the overview tutorial here |
We have already discussed about web application and web framework in our earlier tutorial.
Let’s revisit the same. |
In the image:
Hover from client to web app to and fro Hover from web app to database to and fro |
We see the following:
This exactly what we did while adding the blog and the article. |
Slide: Web framework |
|
[Terminal]
Press Ctrl+C keys |
Let us now stop the server and deactivate the virtual environment.
Press Ctrl and C keys to stop the server. |
[Terminal]
Type deactivate [Enter] |
Then type deactivate and press Enter. |
With this, we come to the end of this tutorial
Let us summarize. | |
Slide: Summary | In this tutorial, we have learnt to
|
Slide: Assignment | Here is an assignment for you.
|
Slide: About Spoken Tutorial project | The video at the following link summarises the Spoken Tutorial project.
Please download and watch it. |
Slide: Spoken Tutorial workshops | The Spoken Tutorial Project team conducts workshops and gives certificates.
For more details, please write to us. |
Slide: Forum for specific questions: | Please post your timed queries in this Forum. |
Slide: FOSSEE to answer questions | Please post your general or technical questions in this Forum. |
Slide: Acknowledgement | Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
More information on this mission is available at this link. |
Slide: Thanks Slide | This script has been contributed by Thiagarajar College of Engineering and the FOSSEE Project, IIT Bombay.
The video has been recorded by Praveen from Spoken Tutorial Project, IIT Bombay. Thanks for watching. |