• Django框架重定向功能


    from django.shortcuts import render,redirect

    # Create your views here.

    from django.shortcuts import HttpResponse

    def login(request):
    if request.method == "GET":
    # 验证逻辑
    user = request.POST.get("user")
    pwd = request.POST.get("pwd")
    if user == "huchangxi" and pwd == "123456":
    #return HttpResponse("用户名或密码验证成功")
    #方法一
    return redirect("/timer")
    #方式二
    import datatime
    now = datetime.datetime.now().strftime("%Y-%m-%d %X")
    return render(request, "app01/timer.html, {"show_time": now})
    else:
    return HttpResponse("用户名或密码验证失败")
    #return render(request, "app02/login.html")
    #return HttpResponse("hello login")


    def index(request):
    return HttpResponse("hello index")
    '''
    def auth(request):
    #验证逻辑
    user = request.POST.get("user")
    pwd = request.POST.get("pwd")
    if user=="huchangxi" and pwd=="123456":
    return HttpResponse("用户名或密码验证失败")
    else:
    return HttpResponse("用户名或密码验证失败")
    '''
    """mysite URL Configuration

    The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.2/topics/http/urls/
    Examples:
    Function views
    1. Add an import: from my_app import views
    2. Add a URL to urlpatterns: path('', views.home, name='home')
    Class-based views
    1. Add an import: from other_app.views import Home
    2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
    Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
    """
    from django.contrib import admin
    from django.urls import path

    #form app01 import views as v1
    #from app02 import views as v2

    from app01.views import get_timer
    from app02.views import login,index
    urlpatterns = [
    path('admin/', admin.site.urls),
    path("timer", get_timer),
    path("index", get_timer),
    path("login/", login),
    path("login", index),
    ]

     

  • 相关阅读:
    HashMap
    Java内部类应用——静态内部类
    transient关键字和@Transient 注解
    java基本数据类型传递与引用传递区别
    抽象类
    java collection-list详解
    Arrays,ArrayList,以及ArrayList源码分析
    【转载】【剑指offer】面试题40:最小的 k 个数中的优先级队列
    java stack总结
    java Queue
  • 原文地址:https://www.cnblogs.com/A121/p/16425388.html
Copyright © 2020-2023  润新知