• Django与HTML业务基本结合--基本的用户名密码提交方法1


     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Title</title>
     6     <style>
     7         label{
     8             width:80px;
     9             text-align:right;
    10             display: inline-block;
    11         }
    12     </style>
    13 </head>
    14 <body>
    15 
    16     <form action="/login" method="post">
    17         <p>
    18             <label for="username">用户名:</label>
    19             <input id="username" type='text'/>
    20         </p>
    21         <p>
    22              <label for="password">密码:</label>
    23              <input id="password" type='text'/>
    24              <input type="submit" value="提交"/>
    25         </p>
    26     </form>
    27 
    28 </body>
    29 </html>
    login.html
     1 from django.shortcuts import render
     2 
     3 # Create your views here.
     4 
     5 
     6 from django.shortcuts import HttpResponse
     7 
     8 def login(request):
     9     f = open('templates/login.html','r',encoding='utf-8')
    10     data = f.read()
    11     f.close()
    12     return HttpResponse(data)
    views.py
     1 """S14Djngo URL Configuration
     2 
     3 The `urlpatterns` list routes URLs to views. For more information please see:
     4     https://docs.djangoproject.com/en/1.11/topics/http/urls/
     5 Examples:
     6 Function views
     7     1. Add an import:  from my_app import views
     8     2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
     9 Class-based views
    10     1. Add an import:  from other_app.views import Home
    11     2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
    12 Including another URLconf
    13     1. Import the include() function: from django.conf.urls import url, include
    14     2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
    15 """
    16 from django.conf.urls import url
    17 from django.contrib import admin
    18 
    19 from cmdb import views
    20 
    21 
    22 
    23 urlpatterns = [
    24     url(r'^admin/', admin.site.urls),
    25     #url(r'^h.html/',views.home),
    26     url(r'^login',views.login),
    27 ]
    urls.py

    打开浏览器访问: http://127.0.0.1:8009/login

  • 相关阅读:
    hdu 1269 迷宫城堡(trajan判环)
    codeforces 591 E. Three States(bfs+思维)
    PowerDesigner 教程
    SQL中inner join、outer join和cross join的区别
    SQL 报表 --简易进销系统
    SQL PROMPT5.3.4.1的一些设置选项
    SQL锁机制和事务隔离级别
    洛谷P1901 发射站
    洛谷P1823 [COI2007] Patrik 音乐会的等待
    洛谷P2947 [USACO09MAR]向右看齐Look Up
  • 原文地址:https://www.cnblogs.com/ujq3/p/7884515.html
Copyright © 2020-2023  润新知