Hands-on-Django
Note: This section covers the basics of setting up a Django project.
Setup Project
-
Create a new Django project:
-
Run the Django development server:
-
Verify that the server is running by visiting http://localhost:8000/ in your web browser.

Working on the App
Create a New App
Configure Django Settings
Add the new app to the INSTALLED_APPS list in your project's settings.py file:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'lynx',
]
Two-Way Template Setup
-
Project-level templates:
- Create a
templatesfolder in the project's root directory. - Configure the
DIRSsetting insettings.pyto include the templates folder.
settings.pyTEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': ['templates'], # here 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] - Create a
-
App-level templates:
- Create a
templatesfolder in the app's directory and start working.
(used in this project)
- Create a
URLs Configuration
-
Create
urls.pyin the app level: -
Link the app-level URLs to the project-level URLs:
Views and Templates
-
Create
views.pyin app level: -
Create
index.htmltemplate in the templates folder of your app.
Static files are not Static?
In Django, static files such as CSS, JavaScript, and images are served directly by the web server.
Static Files Configuration
Follow these steps to configure static files:
-
Create a
staticfolder in the root directory directory of your project.
-
Inside the
staticfolder, create subfolders for CSS, JavaScript, and other assets. -
Configure
settings.pyto include thestaticfolder: -
Load static files in your templates using the
{% load static %}template tag.your_app_name/templates/index.html{% load static %} <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="{% static 'css/styles.css' %}"> <title>Document</title> </head> <body> <h2>Hello World!</h2> </body> <script src="{% static 'js/app.js' %}"></script> </html>
Refresh Static Files
Sometimes changes to static files may not reflect immediately due to browser caching. You can use the following methods to refresh static files:
-
Hard Reload: Developer Tools → Right-click on reload button → Empty Cache.

-
Use Incognito Tab: Open the project in an incognito tab to avoid caching.
(recommended)
Running the Project
Run the Django development server:
If the server starts successfully, and you see the Django welcome page, congratulations! You have successfully set up a basic Django project.