Changes between Initial Version and Version 1 of Ticket #29611


Ignore:
Timestamp:
Jul 30, 2018, 8:03:09 AM (6 years ago)
Author:
Tim Graham
Comment:

The {% url %} template tag uses the reverse() function. You'll need to investigate the issue and explain exactly where the bug is because I'm doubtful that this can't be explained by an expected behavior. By the way, the URL that's returned is based on the order of urlpattterns; INSTALLED_APPS doesn't matter.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29611

    • Property Resolutionneedsinfo
    • Property Status newclosed
  • Ticket #29611 – Description

    initial v1  
    22
    33To explain the problem, lets have the example for url name: "login"
    4 Order of INSTALLED_APPS = [
     4{{{
     5INSTALLED_APPS = [
    56    'django.contrib.admin',
    67    'django.contrib.auth',  # There lies a url named login with pattern /accounts/login
     
    1011    'custom_app',
    1112]
    12 
     13}}}
    1314
    1415Now in the project/urls.py, I provide a different pattern for 'login',
    15 
     16{{{
    1617urlpatterns = [
    1718    # Auth urls
    1819    re_path(r'^login/$', auth_views.login, name='login'),  # I removed the default accounts prefix from the login url
    1920]
    20 
     21}}}
    2122Now, in this case if I do:
    22 reverse("login")  -> the result will be /accounts/login
    23 but if I do: url 'login' in a template -> the result will be /login/
     23`reverse("login")`  -> the result will be `/accounts/login`
     24but if I do: `{% url 'login' %}` in a template -> the result will be `/login/`
Back to Top