zoukankan      html  css  js  c++  java
  • 简单的表单提交

    有一个数据库

    然后创建一个超级用户

    urls.py
    from django.conf.urls import url
    from django.contrib import admin
    from son1.views import *
    urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^index/',index),
    url(r'^$',finish),
    url(r'^logins/',logins),
    ]


    views.py
    from django.shortcuts import render,HttpResponseRedirect
    from django.contrib.auth import login,authenticate
    from django.contrib.auth.decorators import login_required
    # Create your views here.
    def index(request):
    return render(request,'index.html',locals())
    def logins(request):
    username=request.GET.get('username')
    password=request.GET.get('password')
    user=authenticate(username=username,password=password)
    if user is not None:
    if user.is_active:
    login(request,user)
    return HttpResponseRedirect('/')
    return render(request,'index.html',locals())

    def finish(request):
    return render(request,'finish.html',locals())

    index.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>title</title>
    </head>
    <body>
    <form action="/logins" method="get">
    <table>

    <tr><td>用户:</td><td><input type="text" name="username"></td></tr>

    <tr><td>密码:</td><td><input type="password" name="password"></td></tr>

    <tr><td><input type="submit" value="提交"></td></tr>

    </table>
    </form>
    </body>
    </html>


    finish.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    欢迎:{{ user.username }}用户
    </body>
    </html>

  • 相关阅读:
    x64 平台开发 Mapxtreme 编译错误
    hdu 4305 Lightning
    Ural 1627 Join(生成树计数)
    poj 2104 Kth Number(可持久化线段树)
    ural 1651 Shortest Subchain
    hdu 4351 Digital root
    hdu 3221 Bruteforce Algorithm
    poj 2892 Tunnel Warfare (Splay Tree instead of Segment Tree)
    hdu 4031 Attack(BIT)
    LightOJ 1277 Looking for a Subsequence
  • 原文地址:https://www.cnblogs.com/feifang/p/6275008.html
Copyright © 2011-2022 走看看