Jo4nP4l4u
Jo4nP4l4u

Reputation: 105

ERROR 404 Django project has a wrong current path

I was creating a basic website following this tutorial:

https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/skeleton_website

When I tried to redirect the home page to my django app called unihub this error prompted:

Using the URLconf defined in TFGsWeb.urls, Django tried these URL patterns, in this order:

admin/
unihub/
^static\/(?P<path>.*)$
The current path, catalog/, didn't match any of these.

My files look like this:

/TFGsWeb/settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'unihub.apps.UnihubConfig',
]

ROOT_URLCONF = 'TFGsWeb.urls'

STATIC_URL = '/static/'

/TFGsWeb/urls.py

from django.contrib import admin
from django.urls import path

# Use include() to add paths from the unihub application 
from django.urls import include

# Add URL maps to redirect the base URL to our application
from django.views.generic import RedirectView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('unihub/', include('unihub.urls')),
    path('', RedirectView.as_view(url='/unihub/', permanent=True)),
]

# Use static() to add url mapping to serve static files during development (only)
from django.conf import settings
from django.conf.urls.static import static

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

/TFGsWeb/unihub/urls.py

from django.urls import path
from . import views

urlpatterns = [

]

I don't understand why this catalog/ appears when I see no reference to any app or path named catalog/ in the files I did modify.

I'd also like to upload this project to my github so should I just do this for the keys or sensible settings info?

with open('./secret_key.txt') as f:
    SECRET_KEY = f.read().strip()

Upvotes: 2

Views: 535

Answers (2)

Jo4nP4l4u
Jo4nP4l4u

Reputation: 105

Solution:

When I tried to reproduce the "error" in other browsers it didn't happen so my guess is that...

Was not the app itself but the web browser that stored http://127.0.0.1:8000/catalog/ as the link to go to if the web does not have a valid redirect.

Thanks everyone for the support, I changed the url patterns to the suggested ones.

Upvotes: 2

Raydel Miranda
Raydel Miranda

Reputation: 14360

Your unihub application on the mentioned url (/) might be calling (some ajax) or redirecting some catalog app url (specifically catalog/).

Include in your urls the urls from catalog app and/or add such app to your installed apps.

On the other hand, you don't need a RedirectView to point / to your view just write:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('unihub/', include('unihub.urls')),
    path('', include('unihub.urls')),
]

Upvotes: 1

Related Questions