Tuesday, September 12, 2017

More bizarre URL behaviour after deploying

OK, I've more or less solved my original problems in deploying in this space. Well I've deployed and am happy.

BUT, I am still bamboozled by something and wonder if anyone has any clue or insights to share?

I have these two urlpatterns defined:

    url(r'^list/(?P<model>\w+)', views.view_List.as_view(), name='list')
    url(r'^view/(?P<model>\w+)/(?P<pk>\d+)$', views.view_Detail.as_view(), name='view'),

Works a charm with these template tags:

    <a href="{% url 'list' 'Player' %}">List Players</a>
    <a href="{% url 'view' model_name o.pk %}">View Player {{ o }} </a>

That url tag produces these URLs:

    http://127.0.0.1:8000/list/Player
    http://127.0.0.1:8000/view/Player/1

And it works. I click the links and they work. Well I've been developing this way for  a couple of years and it's always worked ;-). it's great!

BUT, after deploying, this resolves on the home page to:

    http://leaderboard.space/list/Player

And when I click it it works! Awesome. Happy as. Great stuff. Gotta love Django!

BUT, if is open this page:

    http://leaderboard.space/view/Player/1

It renders fine, I see a great view of player 1.

BUT, on that page is the good old list link from above, namely:

    <a href="{% url 'list' 'Player' %}">List Players</a>

and on the dev site this resolves to:

    http://127.0.0.1:8000/list/Player

and here is the thing I'm stuck on! On the deployed site it renders as:

    http://leaderboard.space/view/list/Player

What? Where did that 'view' come from? Of course I click it I get a 404 error:

Page not found (404)
Request Method:    GET
Request URL:    http://leaderboard.space/view/list/Player
Using the URLconf defined in CoGs.urls, Django tried these URL patterns, in this order:

  1. ^$ [name='home']
  2. ^admin/
  3. ^login/$ [name='login']
  4. ^logout/$ [name='logout']
  5. ^fix [name='fix']
  6. ^unwind [name='unwind']
  7. ^check [name='check']
  8. ^rebuild [name='rebuild']
  9. ^kill/(?P<model>\w+)/(?P<pk>\d+)$ [name='kill']
  10. ^list/(?P<model>\w+) [name='list']
  11. ^view/(?P<model>\w+)/(?P<pk>\d+)$ [name='view']
  12. ^add/(?P<model>\w+)$ [name='add']
  13. ^edit/(?P<model>\w+)/(?P<pk>\d+)$ [name='edit']
  14. ^delete/(?P<model>\w+)/(?P<pk>\d+)$ [name='delete']
  15. ^leaderboards [name='leaderboards']
  16. ^json/game/(?P<pk>\d+)$ [name='get_game_props']
  17. ^json/leaderboards [name='json_leaderboards']
  18. ^static\/(?P<path>.*)$

The current path, view/list/Player, didn't match any of these.

clearly. Because I don't look for this bizarre and newly introduced 'view'.

Now to be clear, I have a way around this, but I am not looking for a workaround here, I'm fishing for any clues that help me understand how the url template tag generates its output and when and why it inserts a string like this that seems to be the name of the view that the link is on!

Mystery++ and PITA.

Regards,

Bernd.

No comments:

Post a Comment