Thelambofgoat
Thelambofgoat

Reputation: 609

Reverse for url not found in python urlpatterns

I made URL config

urlpatterns = [
  path('', lambda request: redirect('stocks', permanent=False)),
  path('stocks', views.stocks.index, name='stocks.index'),
  path('stocks/<slug:slug>', views.stocks.show, name='stocks.show'),
  path('stocks/<slug:slug>/load', views.stocks.load, name='stocks.load')
]

These URLs are ok, and they work but not first

  path('', lambda request: redirect('stocks', permanent=False)),

It gives when I try http://127.0.0.1:8000

NoReverseMatch at /

Reverse for 'stocks' not found. 'stocks' is not a valid view function or pattern name.

But if I try http://127.0.0.1:8000/stocks all is ok

What's wrong here?

Upvotes: 1

Views: 39

Answers (1)

JPG
JPG

Reputation: 88689

Probably you should use stocks.index instead of stocks

path('', lambda request: redirect('stocks.index', permanent=False)),

Upvotes: 1

Related Questions