Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

Creating an Application in Django

Notes May 10 4

In Django, an application (app) is a self-contained module that implements specific website functionality.Apps help organize project code into reusable, modular components.

For instance, you might create an "articles" app for blog posts, a "users" app for authentication, or a "shop" app for e-commerce features.Each app manages its own data models, views, templates, and related resources.

This modular approach mirrors how frontend developers organize projects into feature-based folders.

Creating an App

Use the startapp management command to generate a new application:

python manage.py startapp articles

This creates an articles directory with the following structure:

articles/
├── __init__.py
├── admin.py
├── apps.py
├── migrations/
├── models.py
├── tests.py
└── views.py

Each file serves a specific purpose:

  • models.py - defines database schemas
  • views.py - handles request processing
  • admin.py - configures admin interface

Creating a View

Open articles/views.py and add a simple view function:

from django.http import HttpResponse

def article_list(request):
    return HttpResponse('Articles Index Page')

This vieew returns a simple HTTP response when accessed.

Configuring URLs

Register the view in you're project's URL configuration.Open demo1/urls.py:

from django.contrib import admin
from django.urls import path
from articles.views import article_list

urlpatterns = [
    path('admin/', admin.site.urls),
    path('articles/', article_list),
]

The path() function maps a URL pattern to a view function.

Testing

Run the development server:

python manage.py runserver

Navigate to http://127.0.0.1:8000/articles/ to see the response.

Registering the App

Before using the app, add it to INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'articles',
]

This registers the app with Django's project system.

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Skipping Errors in MySQL Asynchronous Replication

When a replica halts because the SQL thread encounters an error, you can resume replication by skipping the problematic event(s). Two common approaches are available. Methods to Skip Errors 1) Skip a...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.