The following article explains how to Create a Simple Django App.

  1. Navigate to the root directory of your Django project in the command prompt or terminal.
  2. Create a new app named “myapp” as given below.
python manage.py startapp myapp
  1. So, you will get “myapp” in your project directory, with the following file structure.
myapp/
    migrations/
        __init__.py
    __init__.py
    admin.py
    apps.py
    models.py
    tests.py
    views.py
  1. Open the “views.py” file in your text editor and add the following code.
from django.http import HttpResponse

def index(request):
    return HttpResponse("Hello, world!")

This creates a simple view that returns a “Hello, world!” message when the app is accessed.

  1. Open the “urls.py” file in the “myapp” directory and add the following code.
from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

This maps the root URL of the app to the “index” view that you just created.

  1. Finally, open the “urls.py” file in your project directory and add the following code to include the URLs of your “myapp” app.
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('myapp/', include('myapp.urls')),
    path('admin/', admin.site.urls),
]

This includes the URLs of your “myapp” app under the “/myapp” URL.

  1. Now you can run the development server using the following command.
python manage.py runserver
  1. Open your web browser and go to “http://localhost:8000/myapp/“. The “Hello, world!” message should appear that you defined in your view.

Congratulations, you have created a simple Django app!


Further Reading

Introduction to Django Framework and its Features

Django Practice Exercise

Examples of Array Functions in PHP

Basic Programs in PHP

Registration Form Using PDO in PHP

Inserting Information from Multiple CheckBox Selection in a Database Table in PHP

programmingempire

princites.com