Home > database >  Using the URLconf defined in learning_log.urls, Django tried these URL patterns, in this order:
Using the URLconf defined in learning_log.urls, Django tried these URL patterns, in this order:

Time:10-09

Below are my url patterns from learning logs

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

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

And below is the url I'm adding

"""Defines URL patterns for learning_logs"""

from django.urls import path

from . import views

app_name = 'learning_logs'
urlpatterns = {
# Home page

path('', views.index, name='index'),

# Show all topics
path('topics', views.topics, name='topics'),

# Detail page for a single topic
path(r'^topics/(?P<topic_id>\d )/$', views.topic, name='topic', ),
# Page for adding a new topic
path('new_topic', views.new_topic, name='new_topic'),

}

Below is the error I'm getting from my browser

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

admin/
learning_logs/ new_topic [name='new_topic']
learning_logs/ ^topics/(?P<topic_id>\d )/$ [name='topic']
learning_logs/ topics [name='topics']
learning_logs/ [name='index']
The current path, learning_logs/topics/(?P1\d )/, didn’t match any of these.

You’re seeing this error because you have DEBUG = True in your Django settings file. Change 
that to False, and Django will display a standard 404 page.

My Python version environments are Python 3.10 Django 4.1.1 IDE-PyCharm

CodePudding user response:

Remove the ^ in your url pattern. This char means: beginning of the full url path. but in your case, it is not the beginning of the full path because, your url start by learning_logs/.

CodePudding user response:

This is what I'm getting from terminal after removing ^ ... ?: (2_0.W001) Your URL pattern 'topics/$' [name='topics'] has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path(). ?: (2_0.W001) Your URL pattern 'topics/(?P<topic_id>\d )/$' [name='topic'] has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversig ht when migrating to django.urls.path().

And the browser still have a same output

  • Related