1.创建一个 test_web 项目,和一个 名称为 test_app 的应用,命令如下:
(1)django
-
admin startproject test_web
(2)cd test_web
(3)python manage.py startapp test_app


INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'test_app',
]
3.在test_app中创建templates文件夹,用于放静态网页模板,并在里面存放index.html,代码如下:
<!DOCTYPE html>
<html>
<head>
<title>欢迎光临</title>
</head>
<body>
欢迎光临2018源泉博客园,这是我的第一个Django应用!
</body>
</html>
4.在test_app中的 views.py中创建一个函数index,用于返回index.html;
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request,'index.html')
5.在test_web的url.py中配置与index.html关联的路径,代码如下:
from django.contrib import admin
from django.urls import path
from test_app import views as test_views
from django.conf.urls import include, url
urlpatterns = [
url(r'^$',test_views.index,name='index')
#path('admin/', admin.site.urls),
]
6.启动项目
python manage.py runserver 0.0.0.0:8000
7.打开浏览器:http://localhost:8000/
看看结果哦。。。。