第一步
django-admin startproject HelloWorld
第二步
创建如图所示目录 
index.html
<h1>{{ hello }}</h1>
<p>我爱北京天安门</p>
views.py
from django.shortcuts import render
def runoob(request):
context = {}
context['hello'] = 'Hello World!'
return render(request, 'index.html', context)
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('index/', views.runoob),
]
settings.py
只修改tenplates->dirs部分,记得要引入os库
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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',
],
},
},
]
运行程序
python3 ./HelloWorld/manage.py runserver 0.0.0.0:8000
要找对你的目录下manage.py的路径 ./HelloWorld/manage.py
不知道的话可以 找到manage.py右击  复制相对或绝对路径都可!
结果
 
|