The problem with the url and the views. django



  • There are urls.py,

    urlpatterns = [
    ...,
    url(r'^reviews/', views.reviews),
    url(r'^reviews/page(?P<page>\d+)/$', views.reviews), 
    ]
    

    And there's a view.

    def reviews(request, page):
        ...
    

    Apache makes a mistake:

    reviews() missing 1 required positional argument: 'page', 
    

    but the argument is in view.

    If in url, change

    url(r'^reviews/page(?P<page>\d+)/$', views.reviews), 
    

    url(r'^reviews/page(?P<page_1>\d+)/$', views.reviews), 
    

    And re-enacting the apache, the mistake will be the same, although I think he should be showing such a mistake.

    reviews() missing 1 required positional argument: 'page_1'
    

    If in view.py add default value

    def reviews(request, page=1):
        ...
    

    The mistake disappears, but regardless of the url, the page will always be equal to the meaning of silence.

    Can anyone explain what's going on? django 1.9, apache 2.4.



  • Try this:

    def reviews(request, page=None):
        if page:
            ...
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2