Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django application urls not working

Tags:

django

In one application's urls.py I have:

urlpatterns = patterns('app.views',
    url(r'^products/$', products, name="products"),
    url(r'^$', index, name="index"),
)

In base project urls.py I have:

urlpatterns = patterns('',   
    (r'^$', include('app.urls')),
    (r'^admin/', include(admin.site.urls)),
)

Why http://127.0.0.1:8000/ - works fine with app.views.index method while http://127.0.0.1:8000/products/ - returns 404 error and is not defined in url routes?

Spent some time on it already and can't find solution, maybe there is something simple that I miss...

like image 274
Zelid Avatar asked Nov 07 '10 07:11

Zelid


1 Answers

I was having the same issue while using path() in Django URLs. The simple fix is you don't have to use the slash at the end of the path otherwise Django will take that URL as a complete URL and will not go to the next urls.py file

//this will not work    
path('/', include('app.urls'), name='profile_page')

// but this will work
path('', include('app.urls'), name='profile_page')
like image 159
wetler Avatar answered Oct 16 '22 15:10

wetler