Click here to Skip to main content
15,867,704 members
Articles / Web Development / HTML
Article

Django Development on Android using Pydroid

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
5 May 2020CPOL2 min read 32.7K   261   1   13
Creating a Django app using Pydroid Android app
This is a demonstration of how Pydroid can be used to develop and test a Django application.

Image 1

Background

Django is a web application framework written in Python that helps web developers to build websites faster and without much hassle. It can be of particular use while developing complex database driven websites.

Pydroid is an easy to use and powerful Python IDE for Android. It has a lot of features to develop sophisticated python projects with ease. It also supports various libraries like PyQt5, Kivy, Jupyter, etc. It can be easily used to develop Django applications as well.

In Django, whenever the webserver receives a request for a resource, the urlresolver is used to match the URL with a list of patterns. When it finds the matching pattern, it sends the request to the related function called view. The view performs the required business logic and generates a response, which Django sends to the web browser.

Using the Code

Terminal can be started by choosing the Terminal option in the menu in Pydroid as follows:

Image 2

The following command can be used to install Django after starting terminal in Pydroid:

Image 3

To create a project, you can enter the following command in the directory where you want to create the project:

Image 4

The following directories/files are created:

helloproj/
    manage.py
    helloproj/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

The outer helloproj/ directory is the main container for the project, while the inner helloproj/ directory is the Python package for the project. The helloproj/urls contains the URLs for the project.

To create an application, you can enter the following command after changing to the directory containing the manage.py file:

Image 5

This will create the following directories/files:

helloapp/
    __init__.py
    admin.py
    apps.py
    migrations/
        __init__.py
    models.py
    tests.py
    views.py

Edit the helloapp/views.py file as follows:

Image 6

The above code is for a simple index view, which returns an HttpResponse.

The next step is to map this view to a URL. This can be done by creating the urls.py file in the helloapp directory as follows:

Image 7

After creating the urls.py file in the helloapp directory, the app directory will be as follows:

helloapp/
    __init__.py
    admin.py
    apps.py
    migrations/
        __init__.py
    models.py
    tests.py
    urls.py
    views.py

The next step is to edit the root urls.py file (helloproj/urls.py) as follows:

Image 8

In the above code, the include() function is used to refer to the helloapp.urls file.

Now you can run the server by the $ python manage.py runserver command as follows:

Image 9

After starting the browser and entering the url http://127.0.0.1:8000/helloapp/, it will show the following output:

Image 10

Points of Interest

I hope readers find this article useful and interesting.

History

  • 5th May, 2020: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Instructor / Trainer NIIT, India
India India
I am a trainer by profession. Currently I am working with iFuture Technologies(India) as a Senior Faculty. I enjoy programming as a hobby. During my career I have seen the growth and decline of many technologies, many of them being my favorites like Flash, WPF, Windows Mobile Development. Few of my current favorites are Android, Xamarin and Python, though I also like traditional and evergreen languages like PHP, C#, Visual Basic and Java.

Apart from computers, my favorite pastime is bicycling.

Comments and Discussions

 
PraiseThank You Pin
Baljeet Verma18-Sep-21 16:20
Baljeet Verma18-Sep-21 16:20 
GeneralRe: Thank You Pin
Azim Zahir27-Sep-21 2:32
Azim Zahir27-Sep-21 2:32 
QuestionDjango app Pin
Member 1529520219-Jul-21 22:39
Member 1529520219-Jul-21 22:39 
QuestionServer is not running Pin
zuber ibrahim22-Jun-21 10:30
zuber ibrahim22-Jun-21 10:30 
AnswerRe: Server is not running Pin
Azim Zahir27-Sep-21 2:40
Azim Zahir27-Sep-21 2:40 
QuestionServer is not running Pin
zuber ibrahim22-Jun-21 10:23
zuber ibrahim22-Jun-21 10:23 
I can't run the server "phyton manage.py runserver" because the terminal says "sh:phyton not found"
AnswerRe: Server is not running Pin
Azim Zahir27-Sep-21 2:38
Azim Zahir27-Sep-21 2:38 
SuggestionTermux Pin
Member 150626272-Feb-21 3:41
Member 150626272-Feb-21 3:41 
GeneralRe: Termux Pin
Azim Zahir27-Sep-21 2:35
Azim Zahir27-Sep-21 2:35 
QuestionError in urls.py of helloproj Pin
Member 1489174216-Jul-20 21:23
Member 1489174216-Jul-20 21:23 
SuggestionError Pin
Member 1484145223-May-20 2:50
Member 1484145223-May-20 2:50 
GeneralRe: Error Pin
Azim Zahir4-Jul-20 4:45
Azim Zahir4-Jul-20 4:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.