pythondjangourldjango-viewsurlconf

Django redirecting to wrong view


I have an app called 'vocab', which so far contains a CreateView and a ListView. In my project urls.py file, I have the following:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',views.HomePage.as_view(),name='home'),
    re_path(r"^accounts/", include("accounts.urls", namespace="accounts")),
    re_path(r"^accounts/", include("django.contrib.auth.urls")),
    re_path(r"^logout/$", views.LogOutPage.as_view(), name="logout"),
    re_path(r"^vocab/", include("vocab.urls", namespace="vocab")),
]

And then, in my app urls.py file, I have the following:

urlpatterns = [
    path('list/', views.WordList.as_view(), name="list"),
    path("home/",views.VocabHome.as_view(),name='home'),
    path("create/", views.CreateWord.as_view(), name="create"),
]

And in my html templates I have links to these views. The home and list views work, but when I click on the 'create' link, it takes me to 'list' instead. In the command line I can see that it is accessing /vocab/list/? instead of /vocab/create/. I know the create view works, because if I type it in manually it goes there. And if I delete all the other views it works as well. So it is as if django cannot find the 'create' view when there are others. I've tried my best to solve this problem by making sure all the paths are unique, and I've tried using regular expressions, but it still doesn't work. Any help would greatly be appreciated!


Solution

  • I found the mistake...

    I had a missing form closing tag in my html. This resulted in my second form (and therefore link) being invalid.