lezogeek
lezogeek

Reputation: 27

Django, Path return 404

I've got an issue with my Django app, when i try to browse to http://127.0.0.1:8000/list/ it returns a 404 error :

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

^contact/$
^description/$
^$
myapp/
admin/
The current path, list/, didn't match any of these.

Here my urls.py file :

from django.contrib import admin
from django.urls import path
from django.conf.urls import url
from django.urls import include    
from . import views

urlpatterns = [
    url(r'^contact/$',views.contact),
    url(r'^description/$',views.description),
    url(r'^$',include('myapp.urls')),
    path('myapp/',include('myapp.urls')),
    path('admin/', admin.site.urls),
]

My myapp/urls.py file :

from django.conf.urls import url
from django.urls import path
from . import views

urlpatterns = [
    url(r'^$',views.index),
    url(r'^list',views.list),
    url(r'^Articles/(?P<id>[0-9]+)$', views.details),
]

And this line in my settings.py :

INSTALLED_APPS = [
    'myapp.apps.MyappConfig',
]

Thanks in advance for your help

Upvotes: 0

Views: 259

Answers (1)

Abdul Aziz Barkat
Abdul Aziz Barkat

Reputation: 21787

Change '^list' to '^list/$', having your urls end with a / is important because Django appends slashes by default to any incoming url which doesn't end in one. You can change this by setting APPEND_SLASH = False in the settings. Also you are including myapp.urls twice in your project level urls.
Also in your include:

url(r'^$',include('myapp.urls'))

You are including urls but in the pattern you write ^$. In regex ^ means the string should start from that position and $ means the string should end at that position. Your pattern for views.list end up being ^$^list/$ which is impossible to match. Basically you are preventing any included urls from being matched if you do this. Remove the $ from there.

Upvotes: 1

Related Questions