How to pass a variable from the url to a view in django?

前端 未结 4 366
忘了有多久
忘了有多久 2021-01-16 10:23

Simple question.

How can I pass a variable from the URL to the view? I\'m following the Date Example.

My view needs to arguments:

def hours_         


        
4条回答
  •  心在旅途
    2021-01-16 10:59

    I am not sure I understand your question clearly. Here is my shot at answering based on what I understood.

    Adding a named regex group to your URL configuration should help:

    (r'^plus/(?P\d{1,2})/$', hours_ahead),
    

    This will let you keep the existing view:

    def hours_ahead(request, offset):
        ...
    

提交回复
热议问题