Step-by-Step Guide to Installing Django, Creating a Project and App, and Building a Simple HelloWorld Page
This tutorial explains how to install Django with pip, create a new Django project and app, configure essential files, implement a simple HelloWorld view, and run the development server, providing step‑by‑step commands and code snippets.
This article provides a concise, practical guide for beginners to set up a Django development environment, create a project and an application, and build a minimal HelloWorld web page.
First, install Django in an Anaconda‑managed Python environment using the command: pip install django Next, create a new Django project named myproject with: django-admin startproject myproject After the project is generated, a directory myproject and a manage.py file appear. The key configuration files you will edit are settings.py (for database, static files, and installed apps) and urls.py (for URL routing).
Create a new app called app inside the project: python manage.py startapp app The app scaffold includes several modules such as migrations, admin.py, apps.py, models.py, tests.py, and views.py. For a simple web page you will mainly work with views.py (view functions) and models.py (database models).
To display a HelloWorld page, first register the app in myproject/settings.py. Then add a view function in app/views.py:
from django.shortcuts import render
def test(request):
return render(request, 'test.html')Define the URL pattern in myproject/urls.py to map the route app/test to the view:
from django.urls import path
from app import views
urlpatterns = [
path('app/test', views.test),
]When the server runs, accessing http://127.0.0.1:8000/app/test will render the test.html template.
Start the development server with: python manage.py runserver 8000 Open a browser and navigate to 127.0.0.1:8000/app/test to see the result. The article concludes with a screenshot of the running page and a note that a more complete project will be introduced later.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
