How to make sure a certain django url path is only checked if all the other paths have been checked

I am building an app where users can access their archives through a simple slug, as follows:

lekha.cc/<archive_slug>

This is exactly as instagram does it. However, whenever I go to any other page, such as

lekha.cc/dashboard

The code for the archive view runs, saying that it has not found an archive with that slug. This is an issue for 2 reasons: we dont want any excess code to run, and if a user chooses to name their archive 'dashboard', the entire website would potentially break down since no one would be able to access their dashboard.

My urls.py folder is as follows:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('main.urls'), name='index'),
    path('onboarding/', account_views.onboarding, name='onboarding'),
    path('register/', account_views.register, name='register'),
    path('login/', auth_view.LoginView.as_view(authentication_form=LoginForm, template_name='accounts/login.html'), name="login"),
    path('logout/', account_views.logout_view, name='logout'),
    path('dashboard/', archival_views.dashboard, name='dashboard'),
    path('account_settings/', account_views.account_settings, name='account_settings'),
    path('<str:slug>/', main_views.archive, name='archive'),
    path('item/<str:slug>/', main_views.work, name='work'),
]

Does anyone have any solutions to this issue?

The issue was caused by the browser requesting /favicon.ico/ which django was passing through my view. The url.py file should in theory look through all the URLs in order until it finds the right view, so by default django already checks URLs only once.

The real issue is described further here

Back to Top