简体   繁体   中英

Url change but still on the same page django

When i change to the page "lostitems" it successfull show up, but when i change to another page "addlostitem" it's still on the same page as before, but the url change the way that i want

Urls.py

url(r'lostitems/$', views.LostItemsView.as_view(), name='lost_items'),
url(r'lostitems/addlostitems/$', views.RegisterLostView.as_view(), name='register_lost'),

Views.py

class LostItemsView(generic.ListView):
    model = Wallet
    template_name = 'lostfound/lost_items.html'

class RegisterLostView(View):
    model = Wallet
    template_name = 'lostfound/register_lost.html'

Its because your URL patterns matches (partially) with the first in order, this should fix that:

url(r'^lostitems/$', views.LostItemsView.as_view(), name='lost_items'),
url(r'^lostitems/addlostitems/$', views.RegisterLostView.as_view(), name='register_lost'),

Notice I have added the ^ hat sign in beginning to force full match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM