标签:request def render log username 修改 示例 get .com
urls.py
from django.urls import path from . import views app_name=‘front‘ urlpatterns = [ path(‘‘,views.index,name=‘index‘), path(‘signin/‘,views.login,name=‘login‘) ] ‘‘‘ path(‘signin/‘,views.login,name=‘login‘) 定义一个name 在views中跳转的时候可以使用reverse(‘login‘)来自动转换成signin 避免有更改的时候代码的修改 这种情况下的signin可以任意修改不影响跳转的逻辑 ‘‘‘
views.py
from django.shortcuts import render # Create your views here. from django.http import HttpResponse from django.shortcuts import redirect,reverse def index(request): username = request.GET.get(‘username‘) if username: return HttpResponse(‘前台首页‘) else: login_url=reverse(‘front:login‘) return redirect(login_url) def login(request): return HttpResponse(‘前台登录页面‘)
示例代码:
标签:request def render log username 修改 示例 get .com
原文地址:https://www.cnblogs.com/randomlee/p/10271775.html