创建项目djangotest2
1.创建应用:
python manage.py startapp stu
说明:
admin 管理类
apps 应用类
models 数据库相关
tests 测试
views 识图
2.配置应用
djangotest2/settings.py
INSTALLED_APPS = [
...
'stu'
]
3.配置根路由
djangotest2/urls.py
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^student/', include('stu.urls'))
]
4.创建并配置子路由
# coding=utf-8
from django.conf.urls import url
import views
urlpatterns = {
url(r'^$', views.login_view)
}
说明:
python3导包方式
from . import views
5.创建视图
stu/views.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
def login_view(request):
return render(request, 'login.html')
6.创建页面
templates/login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="" method="get">
<p>
<label>用户名:</label><input type="text" name="uname">
</p>
<p>
<label>密 码:</label><input type="password" name="pwd">
</p>
<p>
<input type="submit" name="登录">
</p>
</form>
</body>
</html>
7.启动并访问
启动:
python manage.py runserver
访问:
http://127.0.0.1:8000/student/
8.补充说明
Django是Python语言写的
采用MVT模型,Model 模型 View视图 Template模板
网友评论