django 역방향 해석

1945 단어
역해석 HttpResponseRedirect-reverse
#student/urls.py

from django.urls import path
from . import views

urlpatterns=[
    path(r'^query1/([0-9]{4})/$', views.queryAll, name='hello'),
    path(r'^$', views.index_view),
]

#student/views.py

from django.http import HttpResponse
from django.shortcuts import render

def queryAll(request,num1):
    print(num1)
    return HttpResponse('hello world')

#          
def index_view(request):
    return render(request,'index.html')

#    
def index_view(request):
  return HttpResponseRedirect(reverse('hello',args=(2018,)))
  
    
    
    

#templates/index.html



    
    Title


    
    방문








4
  • 방식 2
  • 
    #urls.py
    
    from django.urls import path, include
    
    urlpatterns = [
        path(r'^student/', include('student.urls')]
    
    
    #>urls.py
    
    from django.urls import path
    from . import views
    app_name=stu
    
    urlpatterns=[
        path(r'^$', views.Index.as_view()),
        path(r'^query2/',views.Login,name='login')
    ]
    
    
    #views.py
    
    from django.http import HttpResponse, HttpResponseRedirect
    from django.shortcuts import render
    from django.urls import reverse
    from django.views import View
    class Index(View):
        def get(self,request):
            return render(request,'index.html')
    
    
    class Login(View):
        def get(self,request):
            return HttpResponse('hello')
    
    
    #templates/index.html
    
    
    
    
        
        Title
    
    
        방문
    
    
    
    
    
    

    좋은 웹페이지 즐겨찾기